usage points for Homjava string.split () function
The prototype of the String.Split () method in the Java.lang package is:
Public string[] Split (String regex, int limit)
The Split function is used to separate a string into an array of strings using a specific cutter character (regex), and the function returns an array. In each position where the regex appears, it is decomposed.
Note that there are several points to follow:
(1) Regex is optional. A string or regular expression object that identifies whether one or more characters are used to delimit a string. If this option is omitted, an array of single elements containing the entire string is returned.
(2) limit is also optional. This value is used to limit the number of elements returned in an array.
(3) Note the escape character: "." and "|" are escape characters and must be added "\". Similarly: * and + are also so.
If you use the "." As a separate word, it must be worded as follows:
String.Split ("\"), so that the correct separation, can not use String.Split (".");
If you use the "|" As a separate word, it must be worded as follows:
String.Split ("\\|"), so as to correctly separate, can not use String.Split ("|");
(4) If you have more than one separator in a string, you can use the "|" As a hyphen, such as: "Acountid=?" and act_id =? Or extra=? ", separate the three, you can use
String.Split ("And|or");
(5) The result of the split function is closely related to the regex, and several common situations are as follows:
The
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3 |
public class Splittest {public static void main (string [] args) {string str1 = "A-b"; String str2 = "a-b-"; String STR3 = "-a-b"; String STR4 = "-a-b-"; String STR5 = "a"; String STR6 = "-"; String STR7 = "--"; |