Re: Open text file from the from the end backwards

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks for the reply.....Yah, you'd think I could figure this out. I
don't know how to reverse the order of a collection. I guess that's
the problem. I'll keep searching.

Thanks again...

Tom Leylan wrote:
Unless they've changed something in the last decade :-)

You're probably opening the textfile as a "stream of data" in which case you
must read forward. That leaves you with one of two solutions (in my mind.)
If the data isn't going to change as you are reading it you can make two
passes. The first one is to count how many lines you have, then you rewind
and skip as many lines as needed until you get to the point where 20 remain.
Append those to a collection and reverse the order just prior to using it.

The other method permits you to make a single pass but it means you will
store each line into a collection that contains a maximum of 20 items. Each
time you are about to store a new one you see if there are 20 and if so
delete the earliest one. At the end you will have a maximum of 20 items in
the collection. Reverse the order as above.

There is actually a third method. Simply read ever line into the
collection, reverse the order and limit the number of items you display.

Tom


"Stupid48" <cf_rich@xxxxxxxxxxx> wrote in message
news:1168012790.926630.282680@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm trying to do a simple task but can't seem to find a solution. How
do I read lines from a text file backwards.

i.e. I want to select the last 20 lines of a text file and display them
in order starting with the last line first.....

Any assistance would be greatly appreciated....

Thanks, Chris


.



Relevant Pages

  • Re: How good an encryption algorithm is this?
    ... I *do* need to actually reverse the process. ... Like I say, I don't need it to be *absolutely 100%* secure, but I was just ... wasn't quite as good as a professional API based solution, ... store the username in plaintext and store the password ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How good an encryption algorithm is this?
    ... I *do* need to actually reverse the process. ... Like I say, I don't need it to be *absolutely 100%* secure, but I was just ... wasn't quite as good as a professional API based solution, ... store the username in plaintext and store the password ...
    (microsoft.public.vc.language)
  • Re: Open text file from the from the end backwards
    ... Append those to a collection and reverse the order just prior to using it. ... reverse the order and limit the number of items you display. ... do I read lines from a text file backwards. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Open text file from the from the end backwards
    ... Append those to a collection and reverse the order just prior to using it. ... store each line into a collection that contains a maximum of 20 items. ... reverse the order and limit the number of items you display. ... do I read lines from a text file backwards. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Assigning class instance to an array doubt
    ... > If class B derives from class A and we create an array of class B like ... > How can we store firstInstanceOfA in arrayOfB? ... But the reverse is not ...
    (comp.lang.cpp)