How to split a string by multiple characters using the split method? This article provides the implementation methods of vs2005 and vs2003. vs2005 can use the following methods:
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(); }
Use the following method in vs2003:
1. Separated by strings:
Using system. Text. regularexpressions;
String STR = "aaajsbbbjsccc ";
String [] sarray = RegEx. Split (STR, "JS", regexoptions. ignorecase );
Foreach (string I in sarray) response. Write (I. tostring () + "");
Output result: aaa bbb ccc
2. Separate multiple characters:
String STR = "aaajbbbscccjdddseee ";
String [] sarray = Str. Split (New char [2] {'J','s '});
Foreach (string I in sarray) response. Write (I. tostring () + "");
Output: aaa bbb ccc ddd eee
3. Separate them with a single character:
String STR = "aaajbbbjccc ";
String [] sarray = Str. Split ('J ');
Foreach (string I in sarray) response. Write (I. tostring () + "");
Output result: aaa bbb ccc