[Java] [JavaScript] conversion between string arrays and strings (join/split)

Source: Internet
Author: User

Join/split)

1. Java

1-1. String Array => string: stringutils: Join (object [] array, string separator)

Example:/* <Br/> * join strings using separator> AB $ # $ CD $ # $ EF <br/> */</P> <p> Import Org. apache. commons. lang. stringutils; </P> <p> public class stringutilstrial {<br/> Public static void main (string [] ARGs) {</P> <p> // join all strings in the array into a single string, <br/> // separated by $ #$ <br/> system. out. println (stringutils. join (<br/> New String [] {"AB", "cd", "Ef"}, "$ # $ ")); <br/>}< br/>}

 

1-2. String => string array: String: Split (string separator)

Example:Public splitdemo () {<br/> string S = "AB $ # $ CD $ # $ EF"; <br/> // separate each space character. <Br/> string [] Ss = S. Split ("$ # $"); <br/>}

 

2. Javascript

2-1. String Array => string: array: Join (string separator)

Example:<MCE: Script Type = "text/JavaScript"> <br/> <! -- <Br/> var A = new array ("A", "B", "C"); <br/>. join ("|"); <br/> alert (a); <br/> // --> <br/> </MCE: SCRIPT>

 

2-2. String => string array: String: Split (string separator), string: Split (string separator, int length)

Example:<MCE: Script Type = "text/JavaScript"> <br/> <! -- <Br/> var STR = "1234"; <br/> var str1 = "basketball, volleyball, and table tennis"; <br/> var arr = Str. split (""); // all split <br/> var arr1 = str1.split (","); // split by comma <br/> var arr2 = str1.split (",", 2); // split by comma, retain two segments <br/> // --> <br/> </MCE: SCRIPT>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.