用Split函数分隔字符串
using System.Text.RegularExpressions; //不要这个
1、用字符串分隔:
string str="aaajsbbbjsccc";
string[] sArray=Regex.Split(str,"js",RegexOptions.IgnoreCase);
foreach (string i in sArray)
Console.Write(i.ToString() + "/n");
输出结果:
aaa
bbb
ccc
1、用字符串分隔:
string str="aaajsbbbjsccc";
string[] sArray=Regex.Split(str,"js",RegexOptions.IgnoreCase);
foreach (string i in sArray)
Console.Write(i.ToString() + "/n");
输出结果:
aaa
bbb
ccc
2、用多个字符来分隔:
string str="aaajbbbscccjdddseee";
string[] sArray=str.Split(new char[2]{'j','s'});
foreach(string i in sArray)
Console.Write(i.ToString() + "/n");
输出结果:
aaa
bbb
ccc
ddd
eee
3、用单个字符来分隔:
string str="aaajbbbjccc";
string[] sArray=str.Split('j');
foreach(string i in sArray)
Console.Write(i.ToString() + "/n");
输出结果:
aaa
bbb
ccc