README

Path:
README
Modified:
Thu May 08 14:33:41 JST 2003

Description

CSVParser - CSV format parser / generator

About CSVParser

CSVParser is a library to parse and generate CSV(Comma Sepalated Value) format text data. It can do TSV(Tab Sepalated Value) format text data with tab as sepalate delimiter.

CSV format

CSV format is used in many applications, however the applications have own rules. Then CSVParser refers a CSV format generated by Microsoft Excel.

Basic rules are the following:

  However, fields that don't include control characters can be omitted quotes.
  Data outside of quotes is ignored.

ex) ^M = CR + LF

  foo,bar,baz                       -> ["foo","bar","baz"]
  "foo","bar","baz"                 -> ["foo","bar","baz"]
  """foo""","bar",""                -> ["\"foo\"","bar",""]
  "  foo",  bar  ,baz               -> ["  foo","  bar  ","baz"]
  ignore"foo","bar"ignore,"^Mbaz^M" -> ["foo","bar","\r\nbaz\r\n"]

Download

csvparser-0.9.0.tar.gz

Install

Use install.rb or copy csvparser.rb to the directory of voluntary.

  % ruby install.rb config
  % sudo ruby install.rb install

Usage

  require "csvparser"

  csv = CSVParser.new_with_file "csvtext.csv"
  # Displays each csv lines.
  csv.each do | line |
    p line
  end

  # Replaces "<br>" in every fields to return code.
  csv.each_field do | field |
    field.gsub!('<br>', "\n")
  end

License

CSVParser is a free software distributed under the Ruby license.

Author

SUZUKI Tetsuya <suzuki@spice-of-life.net>

Changes

0.9.0(2003/5/8):First release.