split definition and usage The split() method is used to split a string into a string array.
Syntax stringObject.split(separator,howmany)
Parameter Description
separator Required. A string or regular expression to split the stringObject from where specified by this parameter.
howmany optional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings will be returned than the array specified by this parameter. If this parameter is not set, the entire string will be split regardless of its length.
Return value
A string array. The array is created by splitting the string stringObject into substrings at the boundaries specified by separator. The strings in the returned array do not include the separator itself.
However, if separator is a regular expression containing subexpressions, then the returned array includes strings matching those subexpressions (but not text matching the entire regular expression).
Let me give you an example below
]
Advanced split skills (processing of special strings):
There is the String.split() method in the java.lang package, and the return is an array
I use it in my application Let me summarize some of them for your reference only:
1. If "." is used as a separation, it must be written as follows: String.split("\."), so that it can be separated correctly. To separate, you cannot use String.split(".");
2. If you use "|" as a separation, it must be written as follows: String.split("\|"), so that it can be separated correctly. , cannot use String.split("|");
3. If "" is used as separation, it must be written as follows: String.split(\), so that it can be separated correctly. String.split cannot be used ("");
".", "|" and "" are all escape characters, and "\" must be added;
3. If there are multiple delimiters in a string, you can use "|" is used as a hyphen, for example: "acount=? and uu =? or n=?", to separate all three, you can use String.split("and|or");
example 1:
If you want to use the "" character in a string, you also need to escape it. For example, if you want to express the string "aaaabbbb" first, you should use "aaaa\bbbb". If you want to separate it, you should get it like this. Correct result:
String[] aa = "aaa\bbb\bccc".split(\\);
Example 2: