C#实现字符串按多个字符采用Split方法分割
2021-05-04 09:29
标签:system .text bbb this start text post 单个字符 ==
原文:C#实现字符串按多个字符采用Split方法分割
String字符串如何按多个字符采用Split方法进行分割呢?本文提供VS2005和VS2003的实现方法,VS2005可以用下面的方法:
string agentInfo = userInfo.Attribute19.ToString();
string[] myAgent = agentInfo.Split(new string[] { "$#$" }, StringSplitOptions.None);
if (myAgent.Length == 3)
{
this.QLookUpMyAgent.Text = myAgent[0].ToString();
this.QCalenderStartDate.Value = myAgent[1].ToString();
this.QCalenderEndDate.Value = myAgent[2].ToString();
}
VS2003下用下面的方法:
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() + "
");
输出结果:
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() + "
");
输出结果:
aaa
bbb
ccc
ddd
eee
3、用单个字符来分隔:
string str="aaajbbbjccc";
string[] sArray=str.Split(‘j‘);
foreach(string i in sArray) Response.Write(i.ToString() + "
");
输出结果:
aaa
bbb
ccc
C#实现字符串按多个字符采用Split方法分割
标签:system .text bbb this start text post 单个字符 ==
原文地址:http://www.cnblogs.com/lonelyxmas/p/7723297.html
文章标题:C#实现字符串按多个字符采用Split方法分割
文章链接:http://soscw.com/index.php/essay/82215.html