vbscript - CSV Parsing Not Recognizing Line Break (ASP) -
i'm using vbscript parse csv data , display on table. i've got csv set , when open in sublime text, headers , content on different lines (there's 1 row of content besides header). shows 2 lines in sublime text.
the headers don't have comma @ end of row doesn't break , appends first entry of second line on last entry of headers line because it's not technically divided comma.
the code i'm using is:
<html> <head> </head> <body> <%@language="vbscript"%> <table border="1"> <% dim csv_to_read, fso, act csv_to_read="sample.csv" set fso = createobject("scripting.filesystemobject") set act = fso.opentextfile(server.mappath(csv_to_read)) 'read first line of csv, typically these colum headings response.write "<tr><th>" & replace(act.readline,",","</th><th>") & "</th></tr>" & vbcrlf 'read rest of csv response.write "<tr><td>" & replace(replace(act.readall,vbcrlf,"</td></tr>"&vbcrlf&"<tr><td>"),",","</td><td>") & "</td></tr>" %> <caption>total number of records: <%=act.line-1%></caption> </table> </body> </html> why not recognizing line break?
thanks help!
i think problem caused file not having eol marker of vbcrlf (but crlf probably). evidence:
s = "1,2,3" & vblf & "4,5,6" h = "<tr><td>" & replace(replace(s,vbcrlf,"</td></tr>" & vbcrlf & "<tr><td>"),",","</td><td>") & "</td></tr>" wscript.echo "vblf" wscript.echo h s = "1,2,3" & vbcrlf & "4,5,6" h = "<tr><td>" & replace(replace(s,vbcrlf,"</td></tr>" & vbcrlf & "<tr><td>"),",","</td><td>") & "</td></tr>" wscript.echo "vbcrlf" wscript.echo h output:
cscript 23072652.vbs vblf <tr><td>1</td><td>2</td><td>3 4</td><td>5</td><td>6</td></tr> vbcrlf <tr><td>1</td><td>2</td><td>3</td></tr> <tr><td>4</td><td>5</td><td>6</td></tr> (i hope output prove looping advocates double replace produces valid html)
update wrt comment:
this version of script:
s = "1,2,3" & vbcrlf & "4,5,6" wscript.echo ".readall() (faked):" wscript.echo s ' h = "<tr><td>" & replace(replace(s,vbcrlf,"</td></tr>" & vbcrlf & "<tr><td>"),",","</td><td>") & "</td></tr>" ' step step h = replace(s,vbcrlf,"</td></tr>" & vbcrlf & "<tr><td>") wscript.echo "step 1 - eol handling:" wscript.echo h h = replace(h,",","</td><td>") wscript.echo "step 2 - comma handling:" wscript.echo h h = "<tr><td>" & h & "</td></tr>" wscript.echo "step 3 - head & tail i:" wscript.echo h h = "<!doctype html><html><head><title>replace demo</title></head><body><table>" & vbcrlf & h & vbcrlf & "</table></body></html>" wscript.echo "step 4 - head & tail ii:" wscript.echo h output:
cscript 23072652.vbs .readall() (faked): 1,2,3 4,5,6 step 1 - eol handling: 1,2,3</td></tr> <tr><td>4,5,6 step 2 - comma handling: 1</td><td>2</td><td>3</td></tr> <tr><td>4</td><td>5</td><td>6 step 3 - head & tail i: <tr><td>1</td><td>2</td><td>3</td></tr> <tr><td>4</td><td>5</td><td>6</td></tr> step 4 - head & tail ii: <!doctype html><html><head><title>replace demo</title></head><body><table> <tr><td>1</td><td>2</td><td>3</td></tr> <tr><td>4</td><td>5</td><td>6</td></tr> </table></body></html> should make visible how double replace works , parts important.
Comments
Post a Comment