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 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 value: {"1", "2", "3", "", "4 "}
2. public string [] Split (char [] separator, int count)ITPUB personal space, n: H! C0M/S3Uu0002P 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", & q