I use the following code to split the string:
string sss="125asdasdlkmlkdfknkldj125kdjfngdkjfndkg125ksndkfjdks125"; List<String> s = new List<String>(sss.Split("125"));
However, I get a compile-time error:
cannot convert from 'string' to 'char []'
What is the correct way to split a string into another string?
There is no overload for which takes all , use the following closest match instead: String.Splitstring
String.Split
string
List<string> s = new List<string>( sss.Split(new string[] { "125" }, StringSplitOptions.None);
You can simply create char []:
char []
List<String> s = new List<String>(sss.split(new char[] {'1', '2', '5'}))
or
List<String> s = new List<String>(sss.split("125".ToCharArray()));
Additional information: http://msdn.microsoft.com/en-us/library/ezftk57x.aspx
, . "125",
sss.split(new[]{"125"},StringSplitOptions.RemoveEmptyEntries); //or StringSplitOptions.None
if you want to break 1, 2 or 5 anyway, then do
sss.split(new[]{'1','2','5'});
Use an array of strings:
sss.Split(new[]{"125"},StringSplitOptions.None)
Or StringSplitOptions.RemoveEmptyEntries, if you do not need an empty string before the first 125.
StringSplitOptions.RemoveEmptyEntries
Try the following:
//string = "friend&mom&dad&brother" string.Split('&')[int]; //string.Split('&')[0] = "friend"<br> //string.Split('&')[1] = "mom"<br> //string.Split('&')[2] = "dad"<br> //string.Split('&')[3] = "brother"<br>