1. Separated by strings:
Using System. Text. RegularExpressions;
String str = "aaajsbbbjsccc ";
String [] sArray = Regex. Split (str, "js", RegexOptions. IgnoreCase );
Foreach (string I in sArray) Response. Write (I. ToString () + "<br> ");
Output result:
Aaa
Bbb
Ccc
2. Separate multiple characters:
String str = "aaajbbbscccjdddseee"; string [] sArray = str. Split (new char [2] {'J','s '});
Foreach (string I in sArray) Response. Write (I. ToString () + "<br> ");
Output result:
Aaa
Bbb
Ccc
Ddd
Eee
3. Separate them with a single character:
String str = "aaajbbbjccc ";
String [] sArray = str. Split ('J ');
Foreach (string I in sArray) Response. Write (I. ToString () + "<br> ");
Output result:
Aaa
Bbb
Ccc
//////////////////////////////////////// /// // String [] arr = str. split ("o ");
This is a statement with syntax errors. The Split separator parameter should be char [] or string [], and should not be a string. Correct example:
String str = "technology ";
Char [] separator = {'O '};
String [] arr = str. split (separator ); //////////////////////////////////////// //// // String. the 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 instances to explain 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)ITPUB personal space, n: H! C0M/S3U \ u0002P 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
\ U0002w1I + Ch % ^ \ u0017} 0 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: {"1", "2.3, 4"} do not retain the empty element ITPUB personal space 1 K; e \ u0007f \ u0008f} \ u0011C n
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"} to retain null elements, note that the public string [] Split (string [] separator) function is not overloaded, so we cannot be like VB. NET. split (","), but can only use words. split (',')