CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2001
    Location
    Minneapolis, MN, USA
    Posts
    150

    Push back the StreamReader position?

    Is there a way move back the streamreader position? I'm looking for "88," at the beginning of a line and once it is something else it jumps out of the loop. I need to move back the position of the streamreader 1 line, so it can be read later. Is there a way of doing this? Thanks in advance...

    Dim trans_text As String = trans_text.Concat(tmpText, vbCrLf)
    tmpText = myStreamReader.ReadLine()
    Do While tmpText.Substring(0, 3) = "88,"
    If tmpText <> Nothing Then
    trans_text = trans_text.Concat(trans_text, tmpText, vbCrLf)
    Else ' END OF FILE
    Exit Do
    End If
    tmpText = myStreamReader.ReadLine()
    Loop
    Dim srPos As Int32 = CType(myStreamReader.BaseStream.Position, Int32)
    myStreamReader.BaseStream.Position = srPos - 1

  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868
    I think streamreader.BaseStream.Seek() is what you need to look into.

  3. #3
    Join Date
    Aug 2001
    Location
    Minneapolis, MN, USA
    Posts
    150
    How does that work? I looked into the Seek method and I get a integer of 54 back. What is this telling me? Is it a char #?

  4. #4
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    You need to give it the offset in BYTE where you want to place the file pointer at. If you're dealing with a TEXT file, then it should be the char count including the CR and LF.

    -Cool Bizs

  5. #5
    Join Date
    Aug 2001
    Location
    Minneapolis, MN, USA
    Posts
    150
    So how will this work? From the section below, if the StreamReader had the bold line in memory and I was to do a StreamReader.Peek()...How would I check (peek) to see if the next line has "16," in the first 3 positions? Thank you in advance...

    SECTION FROM FILE:
    16,475,13204243,,,04920007747/
    88,OTHER REFERENCE: IA002251916233/
    88,CHECK PAID/
    16,475,13890423,,,04920007718/
    88,OTHER REFERENCE: IA002355033631/
    88,CHECK PAID/

  6. #6
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    I think one solution would be to store the position of the beginning of each lines in an array or collection. So as you read each line, store the current position (.Position from the stream class) which is the beginning of the next line. This way if you need to rewind, you can keep going back to the beginning of each line and search for the number from there.

    -Cool Bizs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured