vb.net - remove dups

XK8ER
XK8ER used Ask the Experts™
on
right now this function will  check with db.txt and new.txt for dups and create a new output.txt with the data shown bellow..
I would like to know how can I make it compatible with new.txt and names like

name3/fsdfsdf/werhfgh/sdfsdf
name4/rtjdas/fsdfhdfh/sdfg

and still generate the same results..

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

>new.txt
name3
name4

>output.txt
name4

Open in new window

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)
        Dim TheDictNew 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)
            If String.IsNullOrWhiteSpace(x) = False And TheDict.ContainsKey(x) = False Then TheDictNew.Add(x, x)
        Next
        IO.File.WriteAllLines(strFileOut, TheDictNew.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 modification done
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)
        Dim TheDictNew 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)
            Dim partialString As String = x.Split("/").First
            If String.IsNullOrWhiteSpace(partialString) = False And TheDict.ContainsKey(partialString) = False Then TheDictNew.Add(partialString, x)

        Next
        IO.File.WriteAllLines(strFileOut, TheDictNew.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