Escape Comma values ​​in quickcsv

I am working on creating csv. I am separating the values ​​separated by a comma (,). If the value in the field contains a comma, then it should not separate the field in excel. Therefore, I want to put a rescue character there. I am using FasterCsv. So how can I put an escape character. What is the quickcsv escape character?

+5
source share
4 answers

Just specify each field (double quotes by default) and the commas inside 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"
+8
source

, : col_sep. , .

+2

If you use FasterCSV methods, this will be automatically fixed!

+1
source

The creative way is to replace the real comma with similar ones. It can be stupid, it all depends on your use case. That was normal for us - I think. I need to post this before I change my mind, lol

my_string.gsub(',','‚')

I'm not sure if this is copied correctly, but you can create it on mac by holding ALT(option) + ,

0
source

All Articles