I am copying sample.csv file’s content into the new.csv file. But I need to add additional column in new.csv file which holds the default value as “Yes” for each row that exists in old file. Here is the code I have written.
Dim ioFile As New System.IO.StreamReader("C:\sample.csv")
Dim ioLine As String
Dim ioLines As String
ioLine = ioFile.ReadLine
ioLines = "ID","Name","Number","Amount","Copied"
ioLines &= vbCrLf & ioLine
While Not ioLine = ""
ioLine = ioFile.ReadLine
ioLines = ioLines & vbCrLf & ioLine
End While
Dim ioWriter As New System.IO.StreamWriter("C:\new.csv")
ioWriter.WriteLine(ioLines)
ioFile.Close()
ioWriter.Close()
The first four columns ID,Name,Number,Amount are present in sample.csv. I am adding additional column Copied which should be “Yes” for each row. Any suggestions please?
Just append the value to the line string in your loop.
EDIT: This should account for your loop condition.
Thanks for the assist, @D..