CSV File to Array Problems with Comma in Field
I am trying to help out a friend with a much easier way to post his tabular data. He usually receives an Excel file containing all the data. I have used some ASP to simply parse through the text file, format and display the results. My problem comes when I have a field that contains a comma (like "LASTNAME, FIRSTNAME"). My script is actually putting the last name and first name in 2 separate fields as well as displaying the commas. Any help would be appreciated. I hope this isn't too confusing...I'm not terribly skilled with ASP.
<%
'Code to display data from the current text-based logfile
Dim objFSO, oInStream, sLine, sSeg
'Define the constants used by the FSO
Const Forreading = 1
'Create an instance of the FSO
Set objFSO = CreateObject("Scripting.fileSystemObject")
'Check the file exists
If objFSO.fileExists( Server.MapPath( "alpha.csv" ) ) Then
'open a file for reading
Set oInStream = objFSO.openTextfile( Server.MapPath( "alpha.csv" ), Forreading, False )
sLine = oInStream.readLine
sSeg = Split( sLine, "," )
%>
<TABLE width="100%" cellpadding="2" cellspacing="0" border="0">
<TR class="headerrow">
<% for loopctr = 0 to ubound(sSeg)
if loopctr > 0 then response.write("<TD width='10' nowrap> </TD>")
response.write ("<TD nowrap>" & sSeg(loopctr) & "</TD>")
next
%>
</TR>
<%
myRow=2
Do Until oInStream.AtEndOfStream
sLine = oInStream.readLine
sSeg = Split( sLine, "," )
if sSeg(0)="" then
else
if myRow=2 then
myRow=1
else
myRow=2
end if
end if
%>
<TR class="bodycopy">
<% for loopctr = 0 to ubound(sSeg)
if loopctr > 0 then response.write("<TD width='10' nowrap class='tablerow" & myRow & "'> </TD>")
response.write ("<TD nowrap class='tablerow" & myRow & "'>" & sSeg(loopctr) & "</TD>")
next
%>
</TR>
<%
loop
%>
</TABLE>
<%
oInStream.Close
Set oInStream = Nothing
else
response.write("Sorry. Information for this event has not been posted. Please check back later.")
end if %>
|