C # Implementation string split by multiple characters using split method

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.