I have a browser text box that my users type into. I am trying the following to split up the contents that they enter by new line. I tried the following but none work. I either get errors or no splitting:
content.Split("\n", StringSplitOptions.None) < gives me an error Error The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
content.Split('\n', StringSplitOptions.None) < gives an error: The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
content.Split(new[] { Environment.NewLine }, StringSplitOptions.None) < doesn't split as needed. When I look at the source in debugger I just see \n characters.
content.Split(new[] { "\r\n" }, StringSplitOptions.None) < doesn't split as needed. When I look at the source in debugger I just see \n characters.
Can anyone suggest what I can do?
Call
content.Splitcorrectly:The third option does not work as in a Windows environment
Environment.NewLineis “\n\r”, but your sting contains only “\n”.In the fourth option you look for “\n\r” again.
Alternatively you could use
This would split on “\r” and “\n” and remove all empty lines.