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

Source: Internet
Author: User

Original article: http://blog.csdn.net/szwangdf/article/details/4177104

 

1. Java

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

Example:

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

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

 
Public splitdemo () {string S = "AB $ # $ CD $ # $ EF"; // separate each space character. String [] Ss = S. Split ("$ # $ ");}

 

2. Javascript

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

Example:

View plain
    1. <MCE: Script Type ="Text/JavaScript">
    2. <! --
    3. VaRA =NewArray ("","B","C");
    4. A. Join ("|");
    5. Alert ();
    6. // -->
    7. </MCE: SCRIPT>

 

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

Example:

View plain
  1. <MCE: Script Type ="Text/JavaScript">
  2. <! --
  3. VaRSTR ="1234";
  4. VaRStr1 ="Basketball, volleyball, and table tennis";
  5. VaRArr = Str. Split ("");// Separate all
  6. VaRArr1 = str1.split (",");// Split by comma
  7. VaRArr2 = str1.split (",", 2 );// Split by comma and retain two segments
  8. // -->
  9. </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.