My question is quite simple. I need to get all text lines from Windows text file.
All lines are separated by \r\n symbols. I use String.Split, but its not cool, because
it only splits ‘by one symbol’ leaving empty string that I need to remove with options flag. Is there a better way?
My implementation
string wholefile = GetFromSomeWhere();
// now parsing
string[] lines = operationtext.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
// ok now I have lines array
UPDATE
File.ReadAllXXX is of no use here coz GetFromSomeWhere is actually RegEx, so I’ve no file after this point.
You can use this overload of
String.Split, which takes an array of strings that can serve as delimiters:Of course, if you already have the file-path, it’s much simpler to use
File.ReadAllLines: