One, single symbol as delimiter
package Com.regix; public class funcspilt { public static void main (string[] args) { /span>// TODO auto-generated method stub St Ring address = "Shanghai | shanghai | Minhang | Wu zhong lu" ; // string[] Splitaddress=address.split (" \\|"); String splitaddress[]=address.split ("\\|" 0]+splitaddress[1]+splitaddress[2]+splitaddress[3]+ splitaddress.length); }}
Two or more symbols as separators
Package Com.regix; Public class funcspilt { publicstaticvoid main (string[] args) { TODO auto-generated method stub String address= "Shanghai ^ Shanghai @ Minhang # Wu Zhong Lu"; String[] splitaddress=address.split ("\\^|@|#"); System.out.println (splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]+ splitaddress.length);} }
Summarize:
(1) The split expression is actually a regular expression. * ^ | A symbol is a character in a regular expression that has a special meaning, and if used as a delimiter, it must be escaped with the escape character, \ \ (2) If multiple separators are used, you need to use | Symbol, as shown in two, but the escape character needs to be added to the delimiter to be processed.
Java's spilt () function