vb.net - find dups and remove

XK8ER
XK8ER used Ask the Experts™
on
hello there,
I have this little function to remove dups but I need a little modification..
as you can see on the text files bellow you run the app and you would get an output.txt with the new data..
the issue is that when I have the new.txt with data like this

name1/kojuhs/judi
name2/juhdi/ijis

it doesn't work anymore.. I need to to work the same way.. how can I do that?

>db.txt
name1/3HGaDXwy/a
name2/iajgL9Aw/b/566/
name3/koyQ5dBp/c/688/956

>new.txt
name1
name2

>output.txt
name3/koyQ5dBp

Open in new window

Public Sub Rem_Dup(ByVal strFileDB As String, ByVal strFileNew As String, ByVal strFileOut As String)
        Dim TheDict As New Dictionary(Of String, String)
        For Each x In IO.File.ReadAllLines(strFileDB)
            If TheDict.ContainsKey(x.Split("/").First) Then Continue For
            TheDict.Add(x.Split("/").First, x)
        Next

        For Each x In IO.File.ReadAllLines(strFileNew)
            If TheDict.ContainsKey(x) Then TheDict.Remove(x)
        Next
        IO.File.WriteAllLines(strFileOut, TheDict.Values.ToList)
    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Project manager
Commented:
Small change done so that he'll find the duplicates
Public Sub Rem_Dup(ByVal strFileDB As String, ByVal strFileNew As String, ByVal strFileOut As String)
        Dim x As String
        Dim TheDict As New Dictionary(Of String, String)

        For Each x In IO.File.ReadAllLines(strFileDB)
            If TheDict.ContainsKey(x.Split("/").First) Then Continue For
            TheDict.Add(x.Split("/").First, x)
        Next

        For Each x In IO.File.ReadAllLines(strFileNew)
            If TheDict.ContainsKey(x.Split("/").First) Then TheDict.Remove(x.Split("/").First)            
        Next
        IO.File.WriteAllLines(strFileOut, TheDict.Values.ToList)
    End Sub

Open in new window

Commented:
Your output file needs just two fields from the db file. I have marked the change needed.
Public Sub Rem_Dup(ByVal strFileDB As String, ByVal strFileNew As String, ByVal strFileOut As String)
        Dim x As String
        Dim TheDict As New Dictionary(Of String, String)

        For Each x In IO.File.ReadAllLines(strFileDB)
            If TheDict.ContainsKey(x.Split("/").First) Then Continue For
            TheDict.Add(x.Split("/").First, x.Split("/").First & "/" & x.Split("/").(1)) 'here is the change needed
        Next

        For Each x In IO.File.ReadAllLines(strFileNew)
            If TheDict.ContainsKey(x.Split("/").First) Then TheDict.Remove(x)            
        Next
        IO.File.WriteAllLines(strFileOut, TheDict.Values.ToList)
    End Sub

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial