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

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()

thanks tinstaafl

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.