The first method:
1 string " ABCDEABCDEABCDE " ; 2 string [] Sarray = S.split ('C'); 3 foreach (string in sarray) 4 Console.WriteLine (i.ToString ()); 5 Console.readkey ();
Output the following result:
Ab
Deab
Deab
De
The second method:
We see the result is a segmentation with a specified character. Use a different construction method to split multiple characters:
1 strings="ABCDEABCDEABCDE";2 string[] Sarray1=s.split (New Char[3]{'C','D','e'}) ;3 foreach(stringIinchsArray1)4Console.WriteLine (i.ToString ());
You can output the following results:
Ab
Ab
Ab
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: UsingSystem.Text.RegularExpressions;
1 string content = "ABC shuangfengdefshuangfeng Ghishuangfeng JKL " ;
2 string [] resultstring = Regex.Split (content, shuangfeng " , Regexoptions.ignorecase);
3 foreach (string i in resultstring)
4 Console.WriteLine (i.ToString ());
5 Console.readkey ();
Output the following result:
Abc
Def
Ghi
Jkl
The fourth method:
1 stringSTR1 ="I love * * * * * * * * *";2 string[] str2;3STR1 = str1. Replace ("*****","*");4STR2 = str1. Split ('*');5 foreach(stringIinchstr2)6 Console.Write (i.ToString ());7Console.readkey ();
The most common use is: str. Replace ("\ r \ n", "\ R"). Split (' \ R ')
The Fifth method:
Stringstr1= "I love * * * * * * * * * * * * * * *;
I want to show the result: I love my family.
If I use the fourth method above, it will produce the following error: I love my family. 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:
1 string " I love * * * * * * * * * " ; 2 string @" \*+ " ); 3 foreach (string in str2) 4 Console.Write (i.ToString ()); 5 Console.readkey ();