Read text file from bottom up?

R

Robbie

Anybody out there know of a way to read a text file starting from the
bottom of the file then going backwards line by line? I am reading
large log files in which the data I'm looking for is always near the
bottom.

I would like something like:

StreamReader sr = new StreamReader("MyFile.txt");
string line = sr.ReadLine(-1); <-- this functionality doesn't exist.

or

string line = sr.ReadPreviousLine();

Any ideas?
 
G

Guest

Assuming you read in the file line by line into a var called readInput, delimetting each line by a ","
Here is an example

string readInput = "line1,line2,line3"
string[] buffer = readInput.Split(",".ToCharArray())

for(int i = (buffer.Length - 1); i > -1; i--
Console.WriteLine(buffer);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top