B
Bjorn Brox
RobinS skrev:
What about this, it first reduce the possible "\r\n" or "\r" instances
down to a single "\n", and then performs a split on the remaining '\n':
String[] lines = myText.Replace("\r\n", "\n").Replace("\r",
"\n").Split('\n');
Jon Skeet said:If you don't know how the strings are "newlined", couldn't you test
for \n,
\r, and \r\n? This is how I do it. Note that the order of entries in
crlfs
is important.
string[] crlfs = { "\r\n", "\n", "\r" };
string[] lines = myText.Split(crlfs, StringSplitOptions.None);
Unless you really need to keep empty lines, that's more easily don as:
string[] lines = myText.Split(new[] {'\r', '\n'},
StringSplitOptions.RemoveEmptyEntries);
<snip>
Cool. I actually DO need the empty lines. I am using it to stuff
persisted text into a multi-line textbox, so rather than "string[]
lines", my code says "myTextBox.Lines = ..."
Thanks for the tip, though. I'll keep it in a handy place.
RobinS.
GoldMail.com
What about this, it first reduce the possible "\r\n" or "\r" instances
down to a single "\n", and then performs a split on the remaining '\n':
String[] lines = myText.Replace("\r\n", "\n").Replace("\r",
"\n").Split('\n');