Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.ruby

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-03-2012, 05:04 AM
john_urban
Guest
 
Posts: n/a
Default Writing CSV file from Array

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

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 09:11 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.