The first 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
The second method:
We see that the result is a split with a specified character. To split multiple characters by using another construction method:
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 ());
You can output the following results:
Ab
Ab
Ab
The third method:
In addition to these two methods, the third approach is to use regular expressions. Create a new console item. Then add the using System.Text.RegularExpressions first;
Copy Code code as follows:
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:
Agc
Mac
Ggg
Ytx
The fourth method:
Copy Code code as follows:
String str1= I am * * * * * * * * * * * * * * * TEACHERS;
String[] str2;
Str1=str1. Replace (*****,*);
Str2=str1. Split (*);
foreach (String i in str2)
Console.WriteLine (i.ToString ());
The Fifth method:
Copy Code code as follows:
String str1= * * * * * * * * * * * * * * * * * * * * teacher;
The result I want to display is: I am a teacher.
If I use the fourth method above, I will create the following error: I am a teacher. There is a space in the middle output, so the output is not the desired result, this is back to the regular expression, then you can use the following fifth method:
String str1= * * * * * * * * * * * * * * * * * * * * teacher;
string[] str2 = System.Text.RegularExpressions.Regex.Split (str1,@[*]+);
foreach (String i in str2)
Console.WriteLine (i.ToString ());
Here through [*]+ cleverly accomplished our goal.