Input
A,1,"Hello, World",Freebasic,9
B,2,Hello World,"Freebasic",5
C,"Hello World","Freebasic"
D,"7",7,"7"
Output
'"A","1","Hello, World","Freebasic","9"
'"B","2","Hello World","Freebasic","5"
'"C","Hello World","Freebasic","",""
'"D","7","7","7",""
Code: Select all
dim as string temp
dim as integer x, y, row, col, qot
'find how many rows in csv file
row = 0
open "data.csv" for input as #1
while not eof (1)
line input #1, temp
row = row + 1
wend
seek #1, 1
'find how many columns in each row of csv file
dim as integer fld(row)
col = 0
for y = 1 to row
line input #1, temp
fld(y) = 1
qot = 0
for x = 1 to len(temp)
if mid(temp,x,1) = chr(34) then qot = qot + 1
if qot = 0 and mid(temp,x,1) = "," then fld(y) = fld(y) + 1
if qot = 2 then qot = 0
next x
if fld(y) > col then col = fld(y)
next y
seek #1, 1
'import data into a 2 dimentional array
dim as string linein(row,col)
for y = 1 to row
for x = 1 to fld(y)
input #1, linein(y,x)
next x
next y
close #1
'save data to csv
open "save.csv" for output as #1
for y = 1 to row
for x = 1 to col
if x < col then
write #1, linein(y,x),
else
write #1, linein(y,x)
end if
next x
next y
close #1