I am using the following code to split a string:
string sss="125asdasdlkmlkdfknkldj125kdjfngdkjfndkg125ksndkfjdks125"; List<String> s = new List<String>(sss.Split("125"));
However, I receive a compile time error:
cannot convert from 'string' to 'char[]'
What is the correct way to split a string by another string?
The String. Insert method creates a new string by inserting a string into a specified position in another string. This method uses a zero-based index. The following example inserts a string into the fifth index position of MyString and creates a new string with this value. C# Copy.
There is no overload for String.Split
which takes just a string
, instead use the next closest match:
List<string> s = new List<string>( sss.Split(new string[] { "125" }, StringSplitOptions.None));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With