-
If it looks ugly, just remove the unnecessary
ToCharArraycall. -
If you want to split by either
\nor\r, you’ve got two options:-
Use an array literal – but this will give you empty lines for Windows-style line endings
\r\n:var result = text.Split(new [] { '\r', '\n' }); -
Use a regular expression, as indicated by Bart:
var result = Regex.Split(text, "\r\n|\r|\n");
-
-
If you want to preserve empty lines, why do you explicitly tell C# to throw them away? (
StringSplitOptionsparameter) – useStringSplitOptions.Noneinstead.