how to read csv file which has :quote_char in data field

S

Salil Gaikwad

How to do this using fastercsv?

i want to read data from a csv file and save it into the database.
my file xyz.csv contains following line
,,,,"xyz",,,,
i want o/p of above row
as follows
nil,nil,nil,nil,"\"xyz\"", nil,nil,nil,nil

currently i get
nil,nil,nil,nil,"\"xyz\"",""

i am using following method to read the data
@parsed_file=FasterCSV.read("xyz.csv", :col_sep =>",",
:quote_char=>',', :force_quotes => true)

Regards
Salil
 
J

James Gray

How to do this using fastercsv?

It's not really a good for for FasterCSV for the same reason's I
explained in this message:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/329678
i want to read data from a csv file and save it into the database.
my file xyz.csv contains following line
,,,,"xyz",,,,
i want o/p of above row
as follows
nil,nil,nil,nil,"\"xyz\"", nil,nil,nil,nil

currently i get
nil,nil,nil,nil,"\"xyz\"",""

This seems to work:
=> [nil, nil, nil, nil, "\"xyz\"", nil, nil, nil, nil]
i am using following method to read the data
@parsed_file=FasterCSV.read("xyz.csv", :col_sep =>",",
:quote_char=>',', :force_quotes => true)

Again, do not set :quote_char and :col_sep to the same value. That's
impossible to parse. Also :force_quotes is only used when writing
CSV, not reading it.

James Edward Gray II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,483
Latest member
TedDvb6626

Latest Threads

Top