Here are a few:
1, the simplest and most commonly used method, with a specified character split open vs.net to create a new console project. Then enter the following program under the main () method.
Copy Code code as follows:
String s= "ABCDEABCDEABCDE";
String[] Sarray=s.split (' C ');
foreach (String i in Sarray)
Console.WriteLine (i.ToString ());
Output the following results:
Ab
Deab
Deab
De
2. Using multiple characters for segmentation
Copy Code code 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:
Ab
Ab
Ab
3, the use of regular expressions
Add reference using System.Text.RegularExpressions;
Copy Code code as follows:
String content= "Agcsmallmacsmallgggsmallytx";
String[]resultstring=regex.split (Content, "small", regexoptions.ignorecase)
foreach (String i in resultstring)
Console.WriteLine (i.ToString ());
Output the following results:
Agc
Mac
Ggg
Ytx