Skip to content

Instantly share code, notes, and snippets.

@yucao24hours
Last active October 21, 2016 08:54
Show Gist options
  • Save yucao24hours/9261de4da88a94f46086b76bf6d62284 to your computer and use it in GitHub Desktop.
Save yucao24hours/9261de4da88a94f46086b76bf6d62284 to your computer and use it in GitHub Desktop.
データにダブルクオートがはいっていると Ruby が勝手にエスケープしてくれる https://tools.ietf.org/html/rfc4180
require "csv"
CSV.open("mogemoge.csv", "w+") do |csv|
array = %w(foo bar baz piyo)
double_quoted = array.map{|item| %Q|"#{item}"| }
p double_quoted
csv << double_quoted
end
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 4. in line 1.
$ cat mogemoge.csv
"""foo""","""bar""","""baz""","""piyo"""
@yucao24hours
Copy link
Author

まあそもそもこんな文字列出すことなんてあんまりないとおもうけど...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment