Return to Snippet

Revision: 50386
at August 19, 2011 05:51 by m1b

Initial Code
#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\"\n 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 "\t#{header}=#{value}"

Initial URL

Initial Description
Shows how to read/write fully formatted CSV with Ruby

Initial Title
Ruby CSV writing and reading example with quotes, line breaks and commas in the fields

Initial Tags
ruby, csv

Initial Language