Adding A Column To The Content Of Csv File

sivag

Member
Joined
Jul 10, 2007
Messages
15
Programming Experience
Beginner
HI I HAVE A CSV FILE. NOW I NEED TO ADD A COLUMN to that CSV file.It already has values.Hope al know how a CSV file looks like.Any idea?

Thanks in Advance:)
 
This could be easily accomplished with a few loops, though there may be a better much easier way.

VB.NET:
Dim sr as new system.io.streamreader("c:\test.csv")
Dim strLine as string = sr.readline
Dim sw as new system.io.streamwriter("c:\test_withnewcolumn.csv")
Dim strLine_Extra as string
'set yourvalue = newColumnName for first pass if the first row contains column names
Dim yourValue as string = "NewColumnName"

Do until line is nothing
   
   strLine_Extra = strLine & "," & yourvalue
   sw.writeline(strLine_Extra)
   line = sr.readline
   'assign value to the new column after each pass
   yourvalue = "" 
Loop

I haven't tested the code yet, but I know it is in the right ballpark...Enjoy
 
Back
Top