I want to build a module to combine multiple text file in a .csv file by using vb.net.
My text file data like this:
(T1.txt)
UnitCode|Qty
001|56
002|45
003|100
004|78
005|67

(T2.txt)
UnitCode|Qty
001|78
002|166
003|10
005|12

I want the output like this:
(Output.csv)
UnitCode,T1,T2
001,56,78
002,45,166
003,100,10
004,78,
005,67,12

Anyone expert can help me?

I would create a Dictionary(Of String,String). Then I would read all of the firest file and create dictionary entries where the key is "001", "002", etc and the value was the corresponding value after the key. ie key="001", value="78", etc.

Then I would read all of the second file and if the key did not exiost then I would add it as in the first file. If the key did exist then I would concatenate the value to the existing value. as in

If myDict.HasKey(keyFromFile) Then
    myDict(keyfromFile) &= "," & valueFromFile
Else
    myDict.Add(keyFromFile,valueFromFile)
End If

Once you have done both files you can step through the dictionary to generate the new file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.