From Blog Park http://www.cnblogs.com/yugen/archive/2010/08/18/1802781.html
1. Delimited by string:
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, separated by 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 the characters 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 syntax error statement, Split's separator parameter should be char[] or string[] and should not be a string. The correct example:
STRINGSTR = "Technology";
Char[] Separator = {' O '};
string[] arr = str. Split (separator);////////////////////////////////////////////////////
The String.Split method has 6 overloaded functions: Program code 1) publicstring[] Split (params char[] separator) 2) publicstring[] Split (char[] separator, int count)
3) Public string[] Split (char[] separator, stringsplitoptionsoptions)
4) Public string[] Split (string[] separator, stringsplitoptionsoptions)
5) Public string[] Split (char[] separator, int count,stringsplitoptions options)
6) Public string[] Split (string[] separator, int count,stringsplitoptions options)
Below we have 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: {"1", "2.3", "", "4"}
string[] split = words. Split (new char[] {', ', '. '}); /return: {"1", "2", "3", "", "4"}
2. Public string[] Split (char[] separator, intcount)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: {"1", "2", "3", "4"} do not preserve empty elements
string[] split = words. Split (new char[] {', ', '. '},stringsplitoptions.none);//return: {"1", "2", "3", "", "4"} Leave empty elements
4. Public string[] Split (string[] separator,stringsplitoptions options)Program code string[]split = words. Split (new string[] {",", "."},stringsplitoptions.removeemptyentries);//return: {"1", "2", "3", "4"} do not preserve empty elements
string[] split = words. Split (new string[] {",", "."},stringsplitoptions.none);//return: {"1", "2", "3", "", "4"} Leave empty 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"} does not preserve empty elements
string[] split = words. Split (new char[] {', ', '. '}, 6,stringsplitoptions.none);//return: {"1", "2", "3", "", "4"} Leave empty elements
6. Public string[] Split (string[] separator, int count,stringsplitoptions options)Program code string[]split = words. Split (new string[] {",", "."}, 2,stringsplitoptions.removeemptyentries);//return: {"1", "2.3,,4"} does not preserve empty elements
string[] split = words. Split (new string[] {",", "."}, 6,stringsplitoptions.none);//return: {"1", "2", "3", "", "4"} Reserved empty elements Note that there is no overloaded function public string[] Split (String[]separator), so we can't use Words.split (",") like vb.net, and only use words. Split (', ')
Split string output character array in C #