OT: CSV flavors

Discussion in 'HTML' started by Jeff Thies, Jul 21, 2004.

  1. Jeff Thies

    Jeff Thies Guest

    I'm writing a little utility to insert/edit CSV files as standard
    HTML tables.

    I understand that some CSV files do \" instead of "" to deal with double
    quotes. What exports CSV that way? I haven't seen it.

    I'm trying to figure if I really need to deal with \"!

    Jeff
     
    Jeff Thies, Jul 21, 2004
    #1
    1. Advertising

  2. Jeff Thies

    Toby Inkster Guest

    Jeff Thies wrote:

    > I understand that some CSV files do \" instead of "" to deal with double
    > quotes. What exports CSV that way? I haven't seen it.


    I can imagine that many CSV files exported from SQL databases would do.

    Have you considered CSV files with no escaping for double-quotes at all?

    My solution is to use *tab*-delimited files and ban the use of tabs and
    new lines as part of the data. Dead easy to parse then:

    #!/usr/bin/perl
    $_ = `cat data`;
    @_ = split(/\n/);
    print "<table>\n";
    while ($_ = shift) {
    @a = split(/\t/);
    print '<tr><td>' . join('</td><td>',@a) . "</td></tr>\n";
    }
    print "</table>\n";

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Jul 22, 2004
    #2
    1. Advertising

  3. Jeff Thies

    Jeff Thies Guest

    Toby Inkster wrote:
    > Jeff Thies wrote:
    >
    >
    >>I understand that some CSV files do \" instead of "" to deal with double
    >>quotes. What exports CSV that way? I haven't seen it.

    >
    >
    > I can imagine that many CSV files exported from SQL databases would do.


    OK. I'll bear that in mind.
    >
    > Have you considered CSV files with no escaping for double-quotes at all?


    You mean no "" or no \"?
    >
    > My solution is to use *tab*-delimited files and ban the use of tabs and
    > new lines as part of the data. Dead easy to parse then:
    >
    > #!/usr/bin/perl
    > $_ = `cat data`;
    > @_ = split(/\n/);
    > print "<table>\n";
    > while ($_ = shift) {
    > @a = split(/\t/);
    > print '<tr><td>' . join('</td><td>',@a) . "</td></tr>\n";
    > }
    > print "</table>\n";


    I like tab delimited. Nobody uses tabs in data, but they do use line
    feeds. Then you have to count quotes and glue the lines back together.

    Thanks!
    Jeff
    >
     
    Jeff Thies, Jul 22, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Thompson

    Detecting Unix flavors

    Andrew Thompson, Sep 5, 2004, in forum: Java
    Replies:
    21
    Views:
    1,744
  2. Replies:
    5
    Views:
    1,937
    Andrew Thompson
    Jan 12, 2005
  3. kbutterly
    Replies:
    3
    Views:
    402
    kbutterly
    Jan 30, 2007
  4. Michael Olea

    What to name container "flavors"?

    Michael Olea, Jun 30, 2005, in forum: C++
    Replies:
    2
    Views:
    321
    Michael Olea
    Jul 1, 2005
  5. Christopher
    Replies:
    2
    Views:
    288
    James Kanze
    Feb 1, 2008
Loading...

Share This Page