cannot convert from 'string' to 'char[]' for split

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.


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));

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

Tags:

C#

.Net