Question : VB.Net - Combine two text files into one with matching first column

Hi Experts.  I have two comma delimited text files.  One with four columns and one with two columns. All values are strings.   The first column of each file is an ID string common to both but not necessarily in the same order.  They both have the same number of rows and they shouldnt be any blanks in the files.

I need to take the second column of the file with two columns into the file with four columns, making five columns.   The data in each file must correspond with the ID number of the first columns in both files.

It would be good to have the data in a third file if thats OK
I hope this makes sense

Any help with the code on this would be greatly appreciated.

Answer : VB.Net - Combine two text files into one with matching first column

What about something like this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
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
Random Solutions  
 
programming4us programming4us