[Java] [38] split split the string

Preface:

Is sometimes needed to "a, b, c" this string into the array [a, b, c]

text:

Ordinary circumstances

String str = "a,b,c";
String[] array = str.split(",");

Special case

// special characters in front of the need to add \\
 // | *: ^ @. 
String str = "A | b | c" ; 
String [] Array = str.split ( "\\ |");

A plurality of symbols as a delimiter

String str = "a^b@c#d";
String[] array = str.split("\\^|@|#");

Reference blog:

split Split string (delimiter such as: * ^: |.,) and pay attention to point shrimp _ _ Sina blog
http://blog.sina.com.cn/s/blog_b6487d470101g0hp.html

Guess you like

Origin www.cnblogs.com/huashengweilong/p/11299180.html