|
-
Mar 2nd, 2008, 06:12 PM
#1
Thread Starter
Member
[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.
-
Mar 2nd, 2008, 06:31 PM
#2
Re: [2008]
Thats because you're calling ReadLine twice. Each time it will return a new line from the file.
vb Code:
Dim Reader As New System.IO.StreamReader(MyTempFilePath)
Dim line As String
Do While Reader.Peek() <> -1
line = Reader.ReadLine
If editorstring.Contains(line) Then
MessageBox.Show("String contains: " & line)
End If
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.
-
Mar 2nd, 2008, 06:33 PM
#3
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|