[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?
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
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.
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
Re: Read/compare particular line from textfile