0

Hi, All,

I am just wondering is this is doable. I've tried searching it in google but still no luck. I want to merge my 2 CSV files by column. For example:

File: coded.csv

"Header A","Header B","Header C"
"Data A","Data B","Data C"
"Data A","Data B","Data C"
"Data A","Data B","Data C"
"Data A","Data B","Data C"

File: truth.csv

"Header D","Header E","Header F"
"Data D","Data E","Data F"
"Data D","Data E","Data F"
"Data D","Data E","Data F"
"Data D","Data E","Data F"

Output should be: Final.csv

"Header A","Header B""Header C","Header D","Header E","Header F"
"Data A","Data B","Data C","Data D","Data E","Data F"
"Data A","Data B","Data C","Data D","Data E","Data F"
"Data A","Data B","Data C","Data D","Data E","Data F"
"Data A","Data B","Data C","Data D","Data E","Data F"

Thanks in advance.

-renzlo

2
Contributors
2
Replies
19
Views
4 Years
Discussion Span
Last Post by renzlo
1

Assuming that both files are guaranteed to be the same number of lines, something like this should work:

    Dim testab As New StreamWriter("C:\testab.csv")
    Dim testa As New StreamReader("C:\testa.csv")
    Dim testb As New StreamReader("C:\testb.csv")
    While Not testa.EndOfStream Or Not testb.EndOfStream
        Dim StringToWrite As String = testa.ReadLine + "," + testb.ReadLine
        testab.WriteLine(StringToWrite)
    End While
    testab.Close()
This question has already been answered. 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.