[Java][JavaScript]字符串数组与字符串之间的互转(join/split)

 字符串数组与字符串之间的互转(join/split)

1、Java

     1-1、字符串数组=>字符串:StringUtils: join(Object[] array, String separator)

            例:/* *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: split(String separator)

           例:public SplitDemo() { String s = "AB$#$CD$#$EF"; // 在每个空格字符处进行分解。 String[] ss = s.split("$#$"); }

 

2、JavaScript

     2-1、字符串数组=>字符串:Array: join(String separator)

          例:

 

     2-2、字符串=>字符串数组:String: split(String separator)、String: split(String separator, int length)

          例:

 

你可能感兴趣的:(JavaScript专区,Java专区)