User13839404 User13839404 - 11 months ago 77
C# Question

How to read text file by particular line separator character?

Reading a text file using streamreader.

using (StreamReader sr = new StreamReader(FileName, Encoding.Default))
{
string line = sr.ReadLine();
}


I want to force that line delimiter should be
\n
not
\r
. So how can i do that?

Answer Source
string text = sr.ReadToEnd();
string[] lines = text.Split('\r');
foreach(string s in lines)
{
   // Consume
}