0

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?

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Reverend Jim
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.