C#中Split用法
1、用字符串分隔:
using System.Text.RegularExpressions;//引用命名空间
using System.Text.RegularExpressions;//引用命名空间
string str="aaajsbbbjsccc";
string[] strArray=Regex.Split(str,"js",RegexOptions.IgnoreCase);
foreach (string strSplit in strArray)
{
Response.Write(strSplit.ToString() + "<br>");
}
Result:
aaa
bbb
ccc
2、用多个字符来分隔:
string str="aaajbbbscccjdddseee";
string str="aaajbbbscccjdddseee";
string[] strArray=str.Split(new char[2] {'j','s'});
foreach(string strSplit in strArray)
foreach(string strSplit in strArray)
{
Response.Write(strSplit .ToString() + "<br>");
}
Result:
aaa
bbb
ccc
ddd
eee
3、用单个字符来分隔:
string str="aaajbbbjccc";
string[] strArray=str.Split('j');
foreach(string strSplit in strArray)
{
Response.Write(strSplit.ToString() + "<br>");
}
Result:
aaa
bbb
ccc
aaa
bbb
ccc