Sub Main()
Dim file1 As New Dictionary(Of String, String)
' Load dictionary with ID (key) and data (value)
Using reader As New System.IO.StreamReader("test1.txt")
While Not reader.EndOfStream
Dim str As String = reader.ReadLine()
Dim temp() As String = str.Split(",")
file1.Add(temp(0), str)
End While
End Using
' Update each key in dictionary with data from second file
Using reader As New System.IO.StreamReader("test2.txt")
While Not reader.EndOfStream
Dim str As String = reader.ReadLine()
Dim temp() As String = str.Split(",")
file1(temp(0)) = String.Concat(file1(temp(0)), ",", temp(1))
End While
End Using
' Write out dictionary to new file
Using writer As New System.IO.StreamWriter("result.txt")
For Each item As KeyValuePair(Of String, String) In file1
writer.WriteLine(item.Value)
Next
End Using
End Sub
|