Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape Comma values in fastercsv

I am working on the csv generation. I am seperating values which are seperated by comma(,). If the value in a field contains comma, then it should not seperate the field in excel. So I want to put a escape character there. I am using FasterCsv. So how I can put a escape character. What is the escape character of fastercsv?

like image 748
Aadi Avatar asked Nov 10 '10 11:11

Aadi


1 Answers

Just quote every field (doublequotes by default) and commas inside of them are ignored:

CSV.generate(:col_sep=>',', :quote_char => '"') do |row|
    row << ["Quid, quid", "latinum dictum"]
    row << ["sit, altum", "viditur."]
end
=> "\"Quid, quid\",latinum dictum\n\"sit, altum\",viditur.\n"
like image 68
David Unric Avatar answered Oct 26 '22 04:10

David Unric