"1" single symbol as separator
String address= "Shanghai | shanghai | Minhang, Wu Zhong Lu";
String[]splitaddress=address.split ("\|"); /If the vertical bar is the separator, then split will need to add two slash "\" to escape
System.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);
Stringaddress= "Shanghai, Shanghai Minhang * Wu Zhong Road";
String[]splitaddress=address.split ("\*");
System.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);
stringaddress= "Shanghai: Shanghai: Minhang: Wu Zhong Road";
String[]splitaddress=address.split ("\:");
System.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);
Stringaddress= "Shanghai, Shanghai, Minhang, Wu Zhong Road";
String[]splitaddress=address.split ("\.");
System.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);
stringaddress= "Shanghai ^ Shanghai ^ Minhang ^ Wu Zhong Road";
String[]splitaddress=address.split ("\^");
System.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);
stringaddress= "Shanghai @ Shanghai @ Minhang @ Wu Zhong Road";
String[]splitaddress=address.split ("@");
System.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);
Stringaddress= "Shanghai, Shanghai, Minhang, Wu Zhong Road";
String[]splitaddress=address.split (",");
System.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]); "2" multiple symbols as delimiters
String address= "Shanghai ^ Shanghai @ Minhang, Wu Zhong Road";
String[]splitaddress=address.split ("\^|@|#");
System.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);
***************** format small hint *****************************************
String address = newstring ("192.168.13.240");
string[] str = address.split ("\.");
for (String s:str) {
System.out.println (s);
}
Output format:
192
168
13
240
System.out.println (Splitaddress[0]+splitaddress[1]+splitaddress[2]+splitaddress[3]);
Output format: Shanghai Shanghai City Minhang Wuzhong Road Summary:
(1) The split expression, in fact, is a regular expression. * ^ | symbols in regular expressions belong to a special meaning character, if used as a separator, you must use the escape character that is escaped.
(2) If you use more than one separator, you need to take advantage of the | symbol, as shown in "2", but still need to add the delimiter to handle the escape character.