willlsteele

How can I read a file line by line I want to process each line and perform various tasks on each line (split, various methods on split data, etc).


Re: Visual C# Express Edition Reading file line by line

_Henock_

Here is one way of doing it in c#

using (StreamReader sr = new StreamReader(<FilePath>))

while (!sr.EndOfStream)

DoSomeWork(sr.ReadLine());






Re: Visual C# Express Edition Reading file line by line

insik


If you are expecting an extended character from the line to be read (ex. n, N, etc) be sure to use this:

using
(StreamReader sr = new StreamReader(<FilePath>, System.Text.Encoding.Default))

without the default encoding, those extended characters will be deleted during the ReadLine() call.

It took me a day to find the solution for this. Hope this helps .