The string. split method has six overload functions:
Program code 1) Public String [] Split (Params char [] separator)
2) Public String [] Split (char [] separator, int count)
3) Public String [] Split (char [] separator, stringsplitoptions options)
4) Public String [] Split (string [] separator, stringsplitoptions options)
5) Public String [] Split (char [] separator, int count, stringsplitoptions options)
6) Public String [] Split (string [] separator, int count, stringsplitoptions options)
Below we use some examples to illustrate how to use (the following string words = "1, 2.3, 4 ";):
1. Public String [] Split (Params char [] separator)Program code string [] split = words. split (New char [] {','}); // return value: {"1", "2.3", "", "4 "}
String [] split = words. split (New char [] {',', '. '}); // return: {"1", "2", "3", "", "4 "}
2. Public String [] Split (char [] separator, int count)Program code string [] split = words. split (New char [] {',', '. '}, 2); // return: {"1", "2.3, 4 "}
String [] split = words. split (New char [] {',', '. '}, 6); // return: {"1", "2", "3", "", "4 "}
3. Public String [] Split (char [] separator, stringsplitoptions options)Program code string [] split = words. split (New char [] {',', '. '}, stringsplitoptions. removeemptyentries); // return value: {"1", "2", "3", "4"} empty element not retained
String [] split = words. split (New char [] {',', '. '}, stringsplitoptions. none); // return: {"1", "2", "3", "", "4"} retain null Elements
4. Public String [] Split (string [] separator, stringsplitoptions options)Program code string [] split = words. split (New String [] {",", ". "}, stringsplitoptions. removeemptyentries); // return value: {"1", "2", "3", "4"} empty element not retained
String [] split = words. split (New String [] {",", ". "}, stringsplitoptions. none); // return: {"1", "2", "3", "", "4"} retain null Elements
5. Public String [] Split (char [] separator, int count, stringsplitoptions options)Program code string [] split = words. split (New char [] {',', '. '}, 2, stringsplitoptions. removeemptyentries); // return value: {"1", "2.3, 4"} empty elements are not retained.
String [] split = words. split (New char [] {',', '. '}, 6, stringsplitoptions. none); // return: {"1", "2", "3", "", "4"} retain null Elements
6. Public String [] Split (string [] separator, int count, stringsplitoptions options)Program code string [] split = words. split (New String [] {",", ". "}, 2, stringsplitoptions. removeemptyentries); // return value: {"1", "2.3, 4"} empty elements are not retained.
String [] split = words. split (New String [] {",", ". "}, 6, stringsplitoptions. none); // return: {"1", "2", "3", "", "4"} retain null Elements
Note that there is no overload function Public String [] Split (string [] separator), so we cannot be like VB. net. split (","), but can only use words. split (',')! Many people are wondering why we can change double quotes to single quotes? After reading the overload function above, I should know the answer. ^_^