I am using the following code to split a string:
string sss=\"125asdasdlkmlkdfknkldj125kdjfngdkjfndkg125ksndkfjdks125\";
List s = new List<
That depends on what you wish to achieve. If you wish to split at the string "125" then do
sss.split(new[]{"125"},StringSplitOptions.RemoveEmptyEntries); //or StringSplitOptions.None
if you wish to split at any occurrence of 1, 2 or 5 then do
sss.split(new[]{'1','2','5'});
Try this:
//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>
this error/issue is not present in .NET Core 3.1 but does appear in .NET 4.7.2. This error came up while trying to use C# fiddle (https://dotnetfiddle.net/) to test something and was not getting the same message in my project. The issue was that my project is using .NET Core compiler and the fiddle was not. Once that was updated in the fiddle, the error cleared.
This confused me for a long time. Finally I realised that I had used double instead of single quotes. In other words, I had x.Split(",")
rather than x.Split(',')
.
I changed to single quotes and it worked for me.
You can just create a 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()));
More information: http://msdn.microsoft.com/en-us/library/ezftk57x.aspx
Use a string array:
sss.Split(new[]{"125"},StringSplitOptions.None)
Or StringSplitOptions.RemoveEmptyEntries
if you don't want a blank string for before the first 125.