Ruby CSV写和读示例,字段中有引号换行符和逗号
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ruby CSV写和读示例,字段中有引号换行符和逗号相关的知识,希望对你有一定的参考价值。
Shows how to read/write fully formatted CSV with Ruby
#require 'csv' require 'rubygems' require 'fastercsv' FCSV { |out| out << [:Number,:One,:Two,:Three,:Four] out << [1,"first","second","Third one quoted with a, comma","fourth "double quotes" line break"] out << [2,"erst","zweite","Dritte,mit Komma","viertl"] out << [3,"primero","segundo","tercero","cuarto,con la coma"] } FasterCSV.foreach("sample.csv", {:headers=>true}) { |r| puts "#{r.length} fields: >>#{r.inspect}<<" r.each { |header, value| puts " #{header}=#{value}" } }
以上是关于Ruby CSV写和读示例,字段中有引号换行符和逗号的主要内容,如果未能解决你的问题,请参考以下文章
CSV::MalformedCSVError: 未加引号的字段在 Ruby 中不允许 \r 或 \n