Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reading ASCII file from the end?!

Reading ASCII file from the end?!

Scheduled Pinned Locked Moved C#
helptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MohammadAmiry
    wrote on last edited by
    #1

    I have to read the last 5 lines of several very very huge ASCII files, several times. I want to see if it is possible to read only those last lines, instead of reading the whole junk data and getting to those 5 ending lines. Could someone please help me, how to decrease this amount of waste of cpu time and un-wanted I/O?

    A 1 Reply Last reply
    0
    • M MohammadAmiry

      I have to read the last 5 lines of several very very huge ASCII files, several times. I want to see if it is possible to read only those last lines, instead of reading the whole junk data and getting to those 5 ending lines. Could someone please help me, how to decrease this amount of waste of cpu time and un-wanted I/O?

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      You could set the position in the stream, but im not sure how accurate that would be. The position is the current index in the huge array of bytes that is your text file, so if you knew the length of the text file... For example, you have a text file with 5000 characters in it, you set the position too 4500, and then read the last 500 characters. That way you don't need to waste time reading the first 4500 characters. The only problem is, how do you know where to start reading from? I'll leave that to you ;) to set the position, i think its just: myStream.Position = somewhere; I think it's .Position anyway, it might be .Location, i'm sure you'll find it.

      My current favourite word is: PIE! Good ol' pie, it's been a while.

      P 1 Reply Last reply
      0
      • A Anthony Mushrow

        You could set the position in the stream, but im not sure how accurate that would be. The position is the current index in the huge array of bytes that is your text file, so if you knew the length of the text file... For example, you have a text file with 5000 characters in it, you set the position too 4500, and then read the last 500 characters. That way you don't need to waste time reading the first 4500 characters. The only problem is, how do you know where to start reading from? I'll leave that to you ;) to set the position, i think its just: myStream.Position = somewhere; I think it's .Position anyway, it might be .Location, i'm sure you'll find it.

        My current favourite word is: PIE! Good ol' pie, it's been a while.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Yes, and there is also .Length A) Set the Position to Length B) Read backward until you encounter the fifth newline C) Reverse the string

        M 1 Reply Last reply
        0
        • P PIEBALDconsult

          Yes, and there is also .Length A) Set the Position to Length B) Read backward until you encounter the fifth newline C) Reverse the string

          M Offline
          M Offline
          MohammadAmiry
          wrote on last edited by
          #4

          Thank you! This looks so fine!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups