Re: Open text file from the from the end backwards

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



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: 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: Reversed issuer name returned by X509Certificate.GetIssuerName()
    ... > The order of CN Name in MMC display and WSE Certificate is exactly reverse. ... >> FCL and WSE) is in reverse order from what is displayed in the> Certificates ... I have a certificate with the>> following Issuer's Name from the Certificates MMC: ...
    (microsoft.public.platformsdk.security)
  • Re: Reversed issuer name returned by X509Certificate.GetIssuerName()
    ... > The order of CN Name in MMC display and WSE Certificate is exactly reverse. ... >> FCL and WSE) is in reverse order from what is displayed in the> Certificates ... I have a certificate with the>> following Issuer's Name from the Certificates MMC: ...
    (microsoft.public.dotnet.security)
  • Re: How to sort address book on last names??
    ... [MVP-Outlook] ... "Mortimer Snerdgrass" wrote in message ... >>I thought that I could reverse the first and last names as they appear ... >>Contacts and that get the last name first under the "Display Name" ...
    (microsoft.public.outlook)