|
-
Aug 17th, 2007, 04:27 AM
#1
Thread Starter
Junior Member
Comparing two text files and extracting the unmatched strings
Hi,
In vb.net, how to do a file comparison between two text files and extract out the unmatched string...
I've done the following comparison.. very basic one...
Private Function FileCompare(ByRef NewFile As Array, ByRef OldFile As Array) As String
Dim intI As Integer
Dim strNew, strOld, strTemp As String
Dim intposition As Integer
Dim strchar As String
For intI = LBound(OldFile) To UBound(OldFile)
strOld = OldFile(intI)
If (strOld <> "" And strOld <> " ") Then
intposition = 0
For Each strchar In NewFile
If (strchar <> "" And strchar <> " ") Then
intposition = InStr(strOld, strchar)
If (intposition = 0) Then
strTemp = strTemp & "," & strchar
Else
Exit For
End If
End If
Next
End If
Next
Return strTemp
End Function
But the drawback is,, the strTemp starts to have the first record onwards.. not the unmatched strings...
Any heads up will be much appreciated..
Thanks
-
Aug 17th, 2007, 11:48 AM
#2
Re: Comparing two text files and extracting the unmatched strings
I don't see two text files, but since you are comparing two arrays, you can loop through them both and see what matches up. Maybe this will get you started:
vb.net Code:
Dim oldfile() As String = {"two", "four", "five", "six"}
Dim newfile() As String = {"one", "two", "three", "four"}
For i As Integer = 0 To oldfile.GetUpperBound(0) Step 1
For j As Integer = 0 To newfile.GetUpperBound(0) Step 1
If oldfile(i) = newfile(j) Then
MessageBox.Show("New file contains " & oldfile(i).ToString())
End If
Next j
Next i
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
|