Results 1 to 2 of 2

Thread: Comparing two text files and extracting the unmatched strings

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    29

    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

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    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:
    1. Dim oldfile() As String = {"two", "four", "five", "six"}
    2. Dim newfile() As String = {"one", "two", "three", "four"}
    3.  
    4. For i As Integer = 0 To oldfile.GetUpperBound(0) Step 1
    5.     For j As Integer = 0 To newfile.GetUpperBound(0) Step 1
    6.         If oldfile(i) = newfile(j) Then
    7.             MessageBox.Show("New file contains " & oldfile(i).ToString())
    8.         End If
    9.     Next j
    10. 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
  •  



Click Here to Expand Forum to Full Width