cookiejar
asked on
Loading .csv data into anarray
I am a beginner and would like to know how to load .csv data into an array.
Data:
"Leader",0,"Safety","00.00 ",03/14/20 03,"4 of 5"
"Leader",0,"Plotter","00.0 1",03/21/2 003","-2"
"Super",1,"Printer","00.02 ",04/21/20 12",""
Loaded in rows and would like each comma delimited be a column
Data:
"Leader",0,"Safety","00.00
"Leader",0,"Plotter","00.0
"Super",1,"Printer","00.02
Loaded in rows and would like each comma delimited be a column
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also have a look at this google project.
Definitely for that kind of csv, use a dedicated parser as Valeri mentioned at the start. Personally i found opencsv to be slightly buggy (iirc) and have often used the Ostermiller csv class.
I don't know whether it's a copy-paste error, but your csv looks ill-formed:
I don't know whether it's a copy-paste error, but your csv looks ill-formed:
has an odd number of quotes"Leader",0,"Plotter","00.01",03/21/2003","-2"
ASKER
Instead of reading from a .csv file, the data is stored in a static array.
"Leader",0,"Safety","00.00 ",20130314 ,"4 of 5"
"Leader",0,"Plotter","00.0 1",2013032 1,"-2"
"Super",1,"Printer","00.02 ",20120423 1,""
How would I loop through the array to access for example:
frst row column 1 which is Leader, column 2 which is 0, column 3 which is Safety
second row column 1 which is Leader, column 2 which is 0, column 3 which is Plotter
"Leader",0,"Safety","00.00
"Leader",0,"Plotter","00.0
"Super",1,"Printer","00.02
How would I loop through the array to access for example:
frst row column 1 which is Leader, column 2 which is 0, column 3 which is Safety
second row column 1 which is Leader, column 2 which is 0, column 3 which is Plotter
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://opencsv.sourceforge.net/