I am reading a text file line by line using StreamReader.Readline(). After reading a line i have to check whether some fields of the line which is read are present in the rest of the file or not.

What i am doing is that after reading a line from the file i am passing the streamreader to check whether there are multiple entries. i am trying to use line.Length() to get the length of line, so using this length i can go back to the line
--------------------------------------------------------------------------------------
my code:

Dim pos as Long

   sr = File.OpenText(filepath)

   While sr.Peek() <> -1

        Dim lineRead As String = sr.ReadLine()

        Dim res As Boolean = CheckIfMultipleEntries(sr)

        pos = -pos

        If res Then

           // save data from those lines and skip these lines

         p += lineRead.Length()
       
       End If

     pos = pos + p   // go to the line which is after the lines skiped
     sr.BaseStream.Seek(pos, SeekOrigin.Current)

  End While


Function CheckIfMultipleEntries(ByVal sr1 As StreamReader) As Boolean

    pos = 0

    While sr1.Peek() <> -1

        Dim l As String = sr1.ReadLine()

        //check if line is present in the rest of the file

        pos += l.Length()

    End While


 End Function

-------------------------------------------------------------------------------------

my problem is that it is not giving me the expected line or it is skipping some part of the line.
any suggestions? how can i return back to my line?

maybe its not possible,
maybe this will help u :
vb.net/syntaxt/#readline

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.