Results 1 to 3 of 3

Thread: [RESOLVED] [2008] Compare string to line in txt file

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Resolved [RESOLVED] [2008] Compare string to line in txt file

    I'm trying to see if my string contains a line from a .txt

    This works, but it is reading and showing in the msgbox the next line down from what I want. Also, I don't want it to stop when it hits the first one found. It should keep going until the end of the string.

    What's wrong with the code?

    Code:
            Dim objReader As New System.IO.StreamReader(MyTempFilePath)
    
            Do While objReader.Peek() <> -1
                If editorstring.Contains(objReader.ReadLine) Then
                    MsgBox("String contains: " & objReader.ReadLine)
                End If
            Loop
    Last edited by rhijaen; Mar 2nd, 2008 at 06:34 PM.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008]

    Thats because you're calling ReadLine twice. Each time it will return a new line from the file.



    vb Code:
    1. Dim Reader As New System.IO.StreamReader(MyTempFilePath)
    2.         Dim line As String
    3.  
    4.         Do While Reader.Peek() <> -1
    5.             line = Reader.ReadLine
    6.             If editorstring.Contains(line) Then
    7.                 MessageBox.Show("String contains: " & line)
    8.             End If
    9.         Loop

    Also note that hungarian notation saying "obj" in front of every class instance is just silly, since everything in the .Net framework inherits from object No biggie though.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Re: [2008] Compare string to line in txt file

    Err..oops :P

    It's perfect, thanks.

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