1、用字符串分隔:
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>");
輸出結果:
aaa
bbb
ccc
2、用多個字符來分隔:
string str="aaajbbbscccjdddseee";
string[] sArray=str.Split(new char[2]{'j','s'});
foreach(string i in sArray) Response.Write(i.ToString() + "<br>");
輸出結果:
aaa
bbb
ccc
ddd
eee
3、用單個字符來分隔:
string str="aaajbbbjccc";
string[] sArray=str.Split('j');
foreach(string i in sArray) Response.Write(i.ToString() + "<br>");
輸出結果:
aaa
bbb
ccc
string 的方法中join方法和split方法是相反的
string [] txtLines={fck,fuckdfd,f};
string jn = string.Join("-", txtLines);
jn="fck-fuckdfd-f";