单个字符分割
string s="abcdeabcdeabcde";
string[] sArray=s.Split('c');
foreach(string i in sArray)
Console.WriteLine(i.ToString());
string[] sArray=s.Split('c');
foreach(string i in sArray)
Console.WriteLine(i.ToString());
输出下面的结果:
ab
deab
deab
de
多个字符分割
string s="abcdeabcdeabcde
string[] sArray1=s.Split(new char[3]{'c','d','e'});
foreach(string i in sArray1)
Console.WriteLine(i.ToString());
string[] sArray1=s.Split(new char[3]{'c','d','e'});
foreach(string i in sArray1)
Console.WriteLine(i.ToString());
可以输出下面的结果:
ab
ab
ab
多个字符分割(正则表达式)
string content="agcsmallmacsmallgggsmallytx";
string[]resultString=Regex.Split(content,"small",RegexOptions.IgnoreCase)
foreach(string i in resultString)
Console.WriteLine(i.ToString());
string[]resultString=Regex.Split(content,"small",RegexOptions.IgnoreCase)
foreach(string i in resultString)
Console.WriteLine(i.ToString());
输出下面的结果:
agc
mac
ggg
ytx