By this code.
require 'csv'
CSV.generate('', quote_char: '"') { |csv| csv << ['A','B','C'] }
It returns this.
A,B,C
But I expect this result.
"A","B","C"
Use the force_quotes
option:
puts CSV.generate(quote_char: '"', force_quotes: true) { |csv| csv << ['A','B','C'] }
"A","B","C"
First, your specification of quote_char
is redundant, because this is the default.
quote_char
does not say that quotes must be used, but indicates which quotes to use if something needs to be quoted. In your example, no quotes are needed, so you don't see any affect of the quote character.
If you want to have quotes always, you should set force_quotes: true
.
See for instance here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.