469,328 Members | 1,276 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

CSV

I'd like to to read a CSV file with javascript. (put into an array of
arrays). (The CSV file would be imported from a input type="file")
I'm not sure how to go about this. Hairy regex or some functions based on
iterating through every character?

Anyone done this in javascript? Hints?

Jeff
Jul 23 '05 #1
2 4431
You don't say where you're doing this (server/client browser/WSH?), so
it's difficult to know what might be the best way.

Simplest would be to read in the whole file using the FSO and split
into an array based on the line separator, then iterate through that
array splitting each line into its constituent fields. Watch out for
quoted fields where the value contains a comma. If the line has no
quotes then you can just split on comma, otherwise a regexp or
character-by-character iteration might do it.

You might also try using the "text" ADO driver and just do a "select
all" on the file.
Tim.


"Jeff Thies" <no****@nospam.net> wrote in message
news:mI****************@newsread3.news.atl.earthli nk.net...
I'd like to to read a CSV file with javascript. (put into an array of arrays). (The CSV file would be imported from a input type="file")
I'm not sure how to go about this. Hairy regex or some functions based on iterating through every character?

Anyone done this in javascript? Hints?

Jeff

Jul 23 '05 #2

"Tim Williams" <sa************@THISpacbell.net> wrote in message
news:ET****************@newssvr25.news.prodigy.com ...
You don't say where you're doing this (server/client browser/WSH?), so
it's difficult to know what might be the best way.
It's client side.
I've just about got it written, quoted commas were a small problem, quoted
linefeeds took a bit more work. It's about 1K of code and I'll post it up if
anyone is interested.

Cheers,
Jeff

Simplest would be to read in the whole file using the FSO and split
into an array based on the line separator, then iterate through that
array splitting each line into its constituent fields. Watch out for
quoted fields where the value contains a comma. If the line has no
quotes then you can just split on comma, otherwise a regexp or
character-by-character iteration might do it.

You might also try using the "text" ADO driver and just do a "select
all" on the file.
Tim.


"Jeff Thies" <no****@nospam.net> wrote in message
news:mI****************@newsread3.news.atl.earthli nk.net...
I'd like to to read a CSV file with javascript. (put into an array

of
arrays). (The CSV file would be imported from a input type="file")
I'm not sure how to go about this. Hairy regex or some functions

based on
iterating through every character?

Anyone done this in javascript? Hints?

Jeff


Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by William C. White | last post: by
2 posts views Thread by Albert Ahtenberg | last post: by
3 posts views Thread by James | last post: by
reply views Thread by Ollivier Robert | last post: by
1 post views Thread by Richard Galli | last post: by
4 posts views Thread by Albert Ahtenberg | last post: by
1 post views Thread by inderjit S Gabrie | last post: by
2 posts views Thread by Jack | last post: by
3 posts views Thread by Sandwick | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.