The String. split () method is also available in the java. lang package. Similar to. net, the return is a struct-type array, but there are some tips during use. I will introduce you as follows. For more information, see
For example, Run "2 | 33 | 4". split ("| ")
The result is:
""
2
3
3
4
It's strange, but check the API description to find out why.
Java. lang. string. split
Split Method
Splits a string into substrings and returns the result as a string array.
StringObj. split ([separator, [limit])
Parameters
StringObj
Required. String object or text to be decomposed. This object will not be modified by the split method.
Separator
Optional. A string or regular expression object that identifies whether a string is separated by one or more characters. If this option is ignored, a single array of elements containing the entire string is returned.
Limit
Optional. This value is used to limit the number of elements in the returned array.
Description
The result of the split method is a string array. In stingObj, the position where separator appears must be decomposed.
Therefore, the normal syntax is as follows:
1. If ". ", must be written as follows: String. split (". "), in this way, the correct separation is not allowed using String. split (". ");
2. If "|" is used as the separator, it must be written as follows: String. split ("|"), so that the correct separation is not allowed, String. split ("| ");
"." And "|" are escape characters and must be added "";
3. If a string contains multiple separators, you can use "|" as a hyphen, for example, "a = 1 and B = 2 or c = 3 ", you can use String to separate all three. split ("and | or ");