Text: C # implements a string split by multiple characters using the Split method
How can string strings be split by multiple characters using the split method? This article provides VS2005 and VS2003 implementations, VS2005 can be used in the following ways:
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 use the following method:
1. Delimited by string:
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>");
Output Result:
Aaa
Bbb
Ccc
2, separated by multiple characters:
String str= "Aaajbbbscccjdddseee";
String[] Sarray=str. Split (New char[2]{' J ', ' s '});
foreach (String i in Sarray) Response.Write (i.tostring () + "<br>");
Output Result:
Aaa
Bbb
Ccc
Ddd
Eee
3. Separate the characters with a single character:
String str= "AAAJBBBJCCC";
String[] Sarray=str. Split (' J ');
foreach (String i in Sarray) Response.Write (i.tostring () + "<br>");
Output Result:
Aaa
Bbb
Ccc
C # Implementation string split by multiple characters using split method