Writing CSV file from Array

J

john_urban

I need to put double quotes around String objects from the array, but
not around other types of objects. :force_quotes puts double quotes
around every field. I don't want that. What is the best way to do
this? For example...

a = [["joe","cool",19,1000], ["mary","jane",20,5000]]

CSV.open("new_file.csv", "w", {:force_quotes=>true}) do |csv| a.each
do |r| csv << r end end

gives us this in the csv file:

joe,cool,19,1000
mary,jane,20,5000

I need this:

"joe","cool",19,1000
"mary","jane",20,5000
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top