Read StreamReader in reverse order

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Question123
    New Member
    • Feb 2008
    • 41

    #1

    Read StreamReader in reverse order

    Hi friends

    How to read StreamReader in reverse direction??

    My code is as below

    Dim client As System.Net.WebC lient = New System.Net.WebC lient
    Dim data As Stream = client.OpenRead (urlextract)
    sr = New StreamReader(da ta)


    so i want to read data in sr to be read line by line but condition is that i have to read last line first.

    So how could be done??

    Plz help me

    Thanks in advance.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Question123
    Hi friends

    How to read StreamReader in reverse direction??

    My code is as below

    Dim client As System.Net.WebC lient = New System.Net.WebC lient
    Dim data As Stream = client.OpenRead (urlextract)
    sr = New StreamReader(da ta)


    so i want to read data in sr to be read line by line but condition is that i have to read last line first.

    So how could be done??

    Plz help me

    Thanks in advance.
    Why not read in the correct order into some buffer and then read from that buffer in your required order?

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Originally posted by r035198x
      Why not read in the correct order into some buffer and then read from that buffer in your required order?
      I'm pretty sure that IS the only way to do it.
      Streams are generally one way right?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Plater
        I'm pretty sure that IS the only way to do it.
        Streams are generally one way right?
        Yep. Certainly if they are reading whole lines. If they were reading byte by byte, they could try some hack by creating a RandomAccessFil e class like the one in Java but that is not worth the effort.

        Comment

        • Svinja
          New Member
          • Nov 2007
          • 25

          #5
          Hi, there is a similar thread:

          Comment

          • Question123
            New Member
            • Feb 2008
            • 41

            #6
            Originally posted by Svinja
            Hi, there is a similar thread:
            http://bytes.com/forum/thread250018.html
            Hello
            yes that thread will be given me hint and i have done what i want
            in this way

            Public Function ReadFileInRever seOrder(ByVal myStream As StreamReader) As String()

            'initialize streamreader
            myStream = New StreamReader("c :\myfile.txt")
            '//read all the contents and store in string
            Dim WholeFileString As String = myStream.ReadTo End()
            Dim split(1) As Char
            split(0) = vbNewLine
            Dim Lines() As String = WholeFileString .Split(split(0) )
            Array.Reverse(L ines)
            GetReverseStrin g = Lines

            End Function

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by Question123
              Hello
              yes that thread will be given me hint and i have done what i want
              in this way

              Public Function ReadFileInRever seOrder(ByVal myStream As StreamReader) As String()

              'initialize streamreader
              myStream = New StreamReader("c :\myfile.txt")
              '//read all the contents and store in string
              Dim WholeFileString As String = myStream.ReadTo End()
              Dim split(1) As Char
              split(0) = vbNewLine
              Dim Lines() As String = WholeFileString .Split(split(0) )
              Array.Reverse(L ines)
              GetReverseStrin g = Lines

              End Function
              Now read the first response again and compare.

              Comment

              Working...