Home > Backend Development > C#.Net Tutorial > Example code for string splitting

Example code for string splitting

零下一度
Release: 2017-06-24 09:43:33
Original
1756 people have browsed it

string agentInfo = userInfo.Attribute19.ToString();
         string[] myAgent = agentInfo.Split(new string[] { "$#$" }, StringSplitOptions.None);
                                                                 (myAgent.Length == 3)
                                                                                                                                                                                                                                                         # # This.QCalenderEndDate.Value = myAgent[2].ToString();
    }

Use the following method under VS2003:

1. Separate 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() + "
");

Output result:

aaa

bbb
ccc


2. Use multiple characters to separate:

string str="aaajbbbscccjdddseee ";

string[] sArray=str.Split(new char[2]{'j','s'});

foreach(string i in sArray) Response.Write( i.ToString() + "
");

Output result:

aaa

bbb
ccc
ddd
eee


3. Use a single character to separate:

string str="aaajbbbjccc";

string[] sArray=str.Split('j');

foreach(string i in sArray) Response.Write(i.ToString() + "
");

Output result:

aaa
bbb
ccc


The above is the detailed content of Example code for string splitting. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template