using System.Collections.Generic;
List<string> Convert(string text) {
string[] splitStrings = { Environment.NewLine, "\r\n", "\n" };
string[] textSplit = text.Split(splitStrings, StringSplitOptions.RemoveEmptyEntries);
var list = new List<string>();
for (int i = 0; i < textSplit.Length; i++) {
if (i == 0 && text.StartsWith(Environment.NewLine)) {
list.Add("");
} else if (i == 0 && text.StartsWith("\r\n")) {
list.Add("");
} else if (i == 0 && text.StartsWith("\n")) {
list.Add("");
}
list.Add(textSplit[i]);
if (i < textSplit.Length - 1) {
list.Add("");
} else {
if (text.EndsWith(Environment.NewLine)) {
list.Add("");
} else if (text.EndsWith("\r\n")) {
list.Add("");
} else if (text.EndsWith("\n")) {
list.Add("");
}
}
}
return list;
}
Console.WriteLine("----");
var test1 = Convert("First line\r\nAnd more \r\n in new line\r\n");
foreach (var item in test1) {
Console.WriteLine(item);
}
Console.WriteLine("----");
var test2 = Convert("First line\r\nAnd more \r\n in new line");
foreach (var item in test2) {
Console.WriteLine(item);
}
Console.WriteLine("----");
var test3 = Convert("First line\r\nAnd more \n in new line");
foreach (var item in test3) {
Console.WriteLine(item);
}
Console.WriteLine("----");
var test4 = Convert("\nFirst line\r\nAnd more \r\n in new line\r\n");
foreach (var item in test4) {
Console.WriteLine(item);
}
Console.WriteLine("----");
var test5 = Convert("\nFirst line\r\nAnd more " + Environment.NewLine + "in new line\r\n");
foreach (var item in test5) {
Console.WriteLine(item);
}
Console.WriteLine("----");