The CSV File
---------------------------------------
AB11011469,"This is some free text, as you see it has some commas, thanks",ZJ477190386GB
AC18515742,This is some other free text with no commas,ZJ477191449GB
ac4894221,"Some more, and commas and ""quotes"" as well",ZJ477191302GB
The Code
----------------------------------------
Dim CSVFile, fs, TextLine, CSVArray, i
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set CSVFile = fs.OpenTextFile(Server.MapPath("datafile.csv"),1, true)
While NOT CSVFile.AtEndOfStream
TextLine = CSVFile.ReadLine()
IF TextLine <> "" THEN
CSVArray = Split(TextLine,",")
For i = 0 TO UBound(CSVArray)
response.write "Column [" & i & "]: " & CSVArray(i) & "<br />"
Next
response.write "---------------------------------------------------------<br />"
END IF
Wend
CSVFile.Close
set CSVFile = nothing
set fs=nothing
The actual output
----------------------------------------------------------
Column [0]: AB11011469
Column [1]: "This is some free text
Column [2]: as you see it has some commas
Column [3]: thanks"
Column [4]: ZJ477190386GB
---------------------------------------------------------
Column [0]: AC18515742
Column [1]: This is some other free text with no commas
Column [2]: ZJ477191449GB
---------------------------------------------------------
Column [0]: ac4894221
Column [1]: "Some more
Column [2]: and commas and ""quotes"" as well"
Column [3]: ZJ477191302GB
---------------------------------------------------------
The desired output
------------------------------
Column [0]: AB11011469
Column [1]: "This is some free text, as you see it has some commas, thanks"
Column [2]: ZJ477190386GB
---------------------------------------------------------
Column [0]: AC18515742
Column [1]: This is some other free text with no commas
Column [2]: ZJ477191449GB
---------------------------------------------------------
Column [0]: ac4894221
Column [1]: "Some more, and commas and ""quotes"" as well"
Column [2]: ZJ477191302GB
---------------------------------------------------------
The desired output
------------------------------
Column [0]: AB11011469
Column [1]: This is some free text, as you see it has some commas, thanks
Column [2]: ZJ477190386GB
---------------------------------------------------------
Column [0]: AC18515742
Column [1]: This is some other free text with no commas
Column [2]: ZJ477191449GB
---------------------------------------------------------
Column [0]: ac4894221
Column [1]: Some more, and commas and ""quotes"" as well
Column [2]: ZJ477191302GB
---------------------------------------------------------
Dim CSVFile, fs, TextLine, CSVArray, i
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set CSVFile = fs.OpenTextFile(Server.MapPath("datafile.csv"),1, true)
Dim comma
comma = chr(34) & "," & chr(34)
While NOT CSVFile.AtEndOfStream
TextLine = CSVFile.ReadLine()
IF TextLine <> "" THEN
TextLine = Replace(TextLine,comma,"^^^")
CSVArray = Split(TextLine,",")
For i = 0 TO UBound(CSVArray)
response.write "Column [" & i & "]: " & Replace(CSVArray(i), "^^^",",") & ""
Next
response.write "---------------------------------------------------------"
END IF
Wend
CSVFile.Close
set CSVFile = nothing
set fs=nothing
Column [0]: AB11011469
Column [1]: "This is some free text
Column [2]: as you see it has some commas
Column [3]: thanks"
Column [4]: ZJ477190386GB
---------------------------------------------------------
Column [0]: AC18515742
Column [1]: This is some other free text with no commas
Column [2]: ZJ477191449GB
---------------------------------------------------------
Column [0]: ac4894221
Column [1]: "Some more
Column [2]: and commas and ""quotes"" as well"
Column [3]: ZJ477191302GB
---------------------------------------------------------
Dim CSVFile, fs, TextLine, CSVArray, i
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set CSVFile = fs.OpenTextFile(Server.MapPath("datafile.csv"),1, true)
While NOT CSVFile.AtEndOfStream
TextLine = CSVFile.ReadLine()
IF TextLine <> "" THEN
CSVArray = Split(TextLine,",")
response.write "Column [" & 0 & "]: " & CSVArray(i) & "<br />"
response.write "Column [" & 1 & "]: "
Dim output
output=""
For i = 1 TO UBound(CSVArray)-1
output = output & "," & CSVArray(i)
Next
response.write Mid(output,2,Len(output)) & "<br />"
response.write "Column [" & UBound(CSVArray) & "]: " & CSVArray( UBound(CSVArray) ) & "<br />"
response.write "---------------------------------------------------------<br />"
END IF
Wend
CSVFile.Close
set CSVFile = nothing
Column [0]: AB11011469
Column [1]: "This is some free text, as you see it has some commas, thanks"
Column [4]: ZJ477190386GB
---------------------------------------------------------
Column [0]: AC18515742
Column [1]: This is some other free text with no commas
Column [2]: ZJ477191449GB
---------------------------------------------------------
Column [0]: ac4894221
Column [1]: "Some more, and commas and ""quotes"" as well"
Column [3]: ZJ477191302GB
---------------------------------------------------------
Dim CSVFile, fs, TextLine, CSVArray, i
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set CSVFile = fs.OpenTextFile(Server.MapPath("datafile.csv"),1, true)
Dim quotes
quotes=chr(34) & chr(34)
While NOT CSVFile.AtEndOfStream
TextLine = CSVFile.ReadLine()
IF TextLine <> "" THEN
CSVArray = Split(TextLine,",")
response.write "Column [" & 0 & "]: " & CSVArray(i) & "<br />"
response.write "Column [" & 1 & "]: "
Dim output
output=""
For i = 1 TO UBound(CSVArray)-1
output = output & "," & CSVArray(i)
Next
output = Mid(output,2,Len(output))
output = Replace(output,quotes,"^^^")
output = Replace(output,chr(34), "")
output = Replace(output,"^^^",chr(34))
response.write & "<br />"
response.write "Column [3]: " & CSVArray( UBound(CSVArray) ) & "<br />"
response.write "---------------------------------------------------------<br />"
END IF
Wend
CSVFile.Close
set CSVFile = nothing
Column [0]: AB11011469
Column [1]:
Column [3]: ZJ477190386GB
---------------------------------------------------------
Column [0]: AC18515742
Column [1]:
Column [3]: ZJ477191449GB
---------------------------------------------------------
Column [0]: ac4894221
Column [1]:
Column [3]: ZJ477191302GB
---------------------------------------------------------
Dim CSVFile, fs, TextLine, CSVArray, i
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set CSVFile = fs.OpenTextFile(Server.MapPath("datafile.csv"),1, true)
While NOT CSVFile.AtEndOfStream
TextLine = CSVFile.ReadLine()
IF TextLine <> "" THEN
CSVArray = Split(TextLine,",")
response.write "Column [" & 0 & "]: " & CSVArray(0) & "<br />"
response.write "Column [" & 1 & "]: "
Dim output
output=""
For i = 1 TO UBound(CSVArray)-1
output = output & "," & CSVArray(i)
Next
output = Mid(output,2,Len(output))
output = Replace(output,quotes,"^^^")
output = Replace(output,chr(34), "")
output = Replace(output,"^^^",chr(34))
response.write "<br />"
response.write "Column [3]: " & CSVArray( UBound(CSVArray) ) & "<br />"
response.write "---------------------------------------------------------<br />"
END IF
Wend
CSVFile.Close
set CSVFile = nothing
Open in new window