|
-
Aug 18th, 2009, 05:47 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Read/compare particular line from textfile
Hi,
I have a 2 textfiles with a few lines of text.
e.g. textfile1
pos1:1
pos2:10
pos3:1
pos4:0
e.g. textfile2
pos1:1
pos2:9
pos3:1
pos4:0
I need to open both files and compare the lines without knowing which line is different. (mgsbox (pos2.value)<< something like this)
Anyone?
-
Aug 18th, 2009, 06:02 AM
#2
Re: Read/compare particular line from textfile
Just open the first one, put in array, open the second and go through each line and compare each line with the same position in the array...
Sample..
VB.NET Code:
Dim arrFirst() As String = IO.File.ReadAllLines("PATH")
Dim reader As New IO.StreamReader("PATH")
Dim i As Integer = 0
While True
Dim line As String = reader.ReadLine
If line Is Nothing Then Exit Sub
If arrFirst(i) <> line Then
MsgBox("Not equal")
Exit While
End If
MsgBox("Equal")
i += 1
End While
Last edited by mickey_pt; Aug 18th, 2009 at 06:08 AM.
Reason: Code
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Aug 18th, 2009, 07:26 AM
#3
Thread Starter
PowerPoster
Re: Read/compare particular line from textfile
Thanks mickey, but it seems that I have to correct my question. I do need to know which line is different. Sorry for the misunderstanding.
-
Aug 18th, 2009, 08:21 AM
#4
Re: Read/compare particular line from textfile
Instead of the MsgBox that says not equal you can save the line value to a string, or if are several different lines you can add them to an arraylist...
[EDIT] - The number of the line or the value?
If it's the number it will be the value of i+1.
If it's the line string it will be the line string
Last edited by mickey_pt; Aug 18th, 2009 at 08:23 AM.
Reason: Question
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Aug 18th, 2009, 09:28 AM
#5
Thread Starter
PowerPoster
Re: Read/compare particular line from textfile
Thanks Mick
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
|