The first method:
string s = "ABCDEABCDEABCDE";
string[] Sarray = s.split (' C ');
foreach (String i in Sarray)
Console.WriteLine (i.ToString ());
Console.readkey ();
Output the following result: AB Deab Deab de
The second method: we see that the result is a segmentation with a specified character. Use a different construction method to split multiple characters:strings="ABCDEABCDEABCDE";string[] Sarray1=s.split (New Char[3]{'C','D','e'}) ;foreach(stringIinchsArray1) Console.WriteLine (i.ToString ()); You can output the following result: Ababab The third method: In addition to these two methods, the third method is to use regular expressions. Create a new console project. Then add the reference first:usingSystem.Text.RegularExpressions;stringContent ="Agcyongfa365macyongfa365gggyongfa365ytx";string[] resultstring = regex.split (content,"yongfa365", regexoptions.ignorecase);foreach(stringIinchresultstring) Console.WriteLine (i.ToString ()); Console.readkey (); Output the following result: Agcmacgggytx The Fourth method:stringSTR1 =" * * * * * * * * * * * * * * * * * * * teacher";string[] str2;str1= str1. Replace ("*****","*"); str2= str1. Split ('*');foreach(stringIinchstr2) Console.Write (i.ToString ()); Console.readkey (); most commonly used is: Str. Replace ("/r/n","/ R"). Split ('/ R') The fifth method:stringstr1=" * * * * * * * * * * * * * * * * * * * teacher"I want to show the result: I am a teacher. If I use the fourth method above, it will produce the following error: I am a teacher. There is a space in the middle of the output, so the output is not the result of hope, this is back to the regular expression, then you can use the following fifth method:stringSTR1 =" * * * * * * * * * * * * * * * * * * * teacher";string[] str2 = System.Text.RegularExpressions.Regex.Split (str1,@"/*+");foreach(stringIinchstr2) Console.Write (i.ToString ()); Console.readkey (); here through/*+ Ingenious completion of our goal. Recommendation: Using regular expressions can save a lot of things, so it is recommended that you use this form: string[] str2 = System.Text.RegularExpressions.Regex.Split (str1, @ "/*+", regexoption
C # string Spilt