How to convert string that have \r\n to lines?
For example, take this string:
string source = "hello \r\n this is a test \r\n tested";
and how can I convert that to:
string[] lines ;
//lines[0] = hello;
//lines[1] = this is a test;
//lines[2] = tested ;
Use String.Split Method (String[], StringSplitOptions) like this:
This one will work regardless of whether the source is written with Windows linebreak
\r\nor Unix\n.As other answers mention, you could use
StringSplitOptions.RemoveEmptyEntriesinstead ofStringSplitOptions.Nonewhich, as the name says, removes empty strings (" "does not qualify for being empty, only""does).