CSV parsing with optional spaces between fields

Discussion in 'Ruby' started by Gergely Kontra, May 5, 2005.

  1. Hi!

    I'd like to parse a CVS file, which can contain whitespaces between
    fields, but it seems, that the csv.rb in ruby 1.8.2 doesn't support
    this. What can I do?

    thx in advance
    +-[ Gergely Kontra <> http://www.mcl.hu/~kgergely ]------+
    | PhD Student (Room:IB113) PGP ID: 0x7E3846BF Mobile:(+36 20)356 9656 |
    | Budapest University of Technology and Economics ICQ# 175564914 |
    +------------- "Olyan langesz vagyok, hogy poroltoval kellene jarnom!" -+

    ----- End forwarded message -----
    Gergely Kontra, May 5, 2005
    1. Advertisements

  2. Just in case someone stumbles across this in the Google archive, here
    is the deal:

    If the field is surrounded by quotation marks, any spaces outside
    those quotation marks would be considered malformed.

    If the field is not surrounded by quotation marks, then the space is
    considered part of the field's content. If you don't want it, look at
    String#strip and its cousins.
    Charles Calvert, Oct 26, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.