Let's look at a simple example.
But its array length is 25, rather than 3. The following method replaces "[jb51.net]" with a special character, for example, $.
For example, the following section is split according to [jb51.net ].
Copy codeThe Code is as follows:
String [] arrstr2 = str. Replace ("[jb51.net]", "$"). Split ('$ ');
Let's take a look at other methods, the simplest and most commonly used methods, and open vs.net to create a console project using a specified character. Enter the following program in the Main () method.
Copy codeThe Code is as follows:
String s = "abcdeabcdeabcde ";
String [] sArray = s. Split ('C ');
Foreach (string I in sArray)
Console. WriteLine (I. ToString ());
Output the following results:
Copy codeThe Code is as follows:
AB
Deab
Deab
De
2. Use multiple characters for segmentation
Copy codeThe Code is as follows:
String s = "abcdeabcdeabcde"
String [] sArray1 = s. Split (new char [3] {'C', 'D', 'E '});
Foreach (string I in sArray1)
Console. WriteLine (I. ToString ());
Output the following results:
Copy codeThe Code is as follows:
AB
AB
AB
3. Use Regular Expressions
Add reference
Copy codeThe Code is as follows:
Using System. Text. RegularExpressions;
String content = "agcsmallmacsmallgggsmallytx ";
String [] resultString = Regex. Split (content, "small", RegexOptions. IgnoreCase)
Foreach (string I in resultString)
Console. WriteLine (I. ToString ());
Output the following results:
Copy codeThe Code is as follows:
Agc
Mac
Ggg
Ytx
There is also an uncommon Method
Copy codeThe Code is as follows:
String str = "reterry [jb51.net] is the webmaster of [jb51.net ";
String [] arrstr = str. split (new char [] {'[','s ', 'O','s', 'U', 'O', '8 ','. ', 'C', 'O', 'M','] '});
For (int I = 0; I <arrstr. Length; I ++)
{
Response. Write (arrstr [I]);
}