The difference between Split ("") and split.
- There is a space between Split ("") and ""
String S = "The rain in Spain falls mainly in the plain."; // "there are spaces between them, and each space character is decomposed. String [] Ss = S. split (""); system. out. println ("[ss [0] =" + SS [0] + "]"); system. out. println ("["); For (string: SS) {system. out. println (string);} system. out. println ("]");
Program effect:
[Ss [0] = The]
[
The
Rain
In
Spain
Falls
Mainly
In
The
Plain.
]
========================================================== ==========
- There is no space between Split ("") and ""
String S = "The rain in Spain falls mainly in the plain."; // "there is no space between them. String [] Ss = S. [do not translate, just delete the space! System. out. println ("[ss [0] =" + SS [0] + "]"); system. out. println ("["); For (string: SS) {system. out. println (string);} system. out. println ("]");
Program effect:
[ss[0] =][The rain in Spain falls mainly in the plain.]
This is what I encountered when I split the IP address again today! I have never thoroughly studied it before! Ah .....
Although there are explanations on the internet, I still want to summarize it so that you can make your own things!
String IP = "127.0.0.1"; string [] S = IP. split (". "); <----- the death of the live token to the results for (string: S) {system. out. println (string );}
- Improve the split parameter settings after searching for materials
- Use split ("//.") to split:
String ip = "127.0.0.1"; // String [] s = ip.split(".");String [] s = ip.split("//.");for (String string : s) {System.out.println(string);}
Program running effect: 127001
- Cause Analysis: Split (string RegEx) is a regular expression rather than a normal string.
- Experience Sharing:
- 1. The separator is ". "(no output)," | "(cannot get the correct effect) when escaping characters," * "," + "error throws an exception, you must add "//" to the front, such as split (// | );
- 2. If you use "/" as the separator, you must write it as follows: string. split ("//"), because "//" is used in Java to express "/", the string must be written as follows: string STR = "A // B // C ";
- Escape Character, which must contain "//";
- 3. If a string contains multiple separators, you can use "|" as a hyphen, for example, string STR = "Java string-split # test". You can use Str. split ("|-| #") removes each string;