Need CSV Parser

Discussion in 'ASP .Net' started by Mike Bridge, May 11, 2004.

  1. Mike Bridge

    Mike Bridge Guest

    Can anyone suggest a good CSV parser that I can use from C#?
    I've been using the Ostermiller CSVParser in Java, which is great, but
    I can't find a full-featured C# one yet....

    I need one that:

    - Works for Mac, Windows and Unix end-of-line characters
    - Handles fields with end-of-line characters in the middle of it
    - Doesn't read the entire file into memory (files can be 100000+
    records)
    - Runs as managed code

    (It'd also be nice if it could read non-latin-1 character sets if
    necessary.)

    I've found a few freeware ones, but none satisfies all those
    requirements. I haven't been able to find a commercial one.

    Thanks!

    -Mike
     
    Mike Bridge, May 11, 2004
    #1
    1. Advertising

  2. Mike Bridge

    Ben Dewey Guest

    You can load a csv in as an OLEDB Dataset see this link on for information
    on the connection string and let me know if you have any more questions.
    http://www.able-consulting.com/MDAC/ADO/Connection/ODBC_DSNLess.htm#ODBCDriverForText


    "Mike Bridge" <> wrote in message
    news:...
    > Can anyone suggest a good CSV parser that I can use from C#?
    > I've been using the Ostermiller CSVParser in Java, which is great, but
    > I can't find a full-featured C# one yet....
    >
    > I need one that:
    >
    > - Works for Mac, Windows and Unix end-of-line characters
    > - Handles fields with end-of-line characters in the middle of it
    > - Doesn't read the entire file into memory (files can be 100000+
    > records)
    > - Runs as managed code
    >
    > (It'd also be nice if it could read non-latin-1 character sets if
    > necessary.)
    >
    > I've found a few freeware ones, but none satisfies all those
    > requirements. I haven't been able to find a commercial one.
    >
    > Thanks!
    >
    > -Mike
    >
     
    Ben Dewey, May 11, 2004
    #2
    1. Advertising

  3. Mike Bridge

    Mike Bridge Guest

    That may work with a small file, but these CSV files are pretty large
    to load whole into a DataSet---some of them will take up over a
    megabyte of memory. Since DataSets are connectionless, the ODBC
    Driver would either have to either load the whole thing into memory,
    which would violate constraint #3, or it would have to somehow copy
    and cache the whole file, which would be pretty inefficient.

    Also, it looks like you can't open the file without knowing what the
    format is in advance, which limits its usefulness. Unless I'm missing
    something, it requires a .ini file. Yuck!

    And I'm guessing that if it comes from Microsoft, it's Microsoft-only,
    and would violate constraint #1.

    Thanks for the suggestion, though.

    -Mike



    On Tue, 11 May 2004 13:40:57 -0400, "Ben Dewey"
    <> wrote:

    >You can load a csv in as an OLEDB Dataset see this link on for information
    >on the connection string and let me know if you have any more questions.
    >http://www.able-consulting.com/MDAC/ADO/Connection/ODBC_DSNLess.htm#ODBCDriverForText
    >
    >
    >"Mike Bridge" <> wrote in message
    >news:...
    >> Can anyone suggest a good CSV parser that I can use from C#?
    >> I've been using the Ostermiller CSVParser in Java, which is great, but
    >> I can't find a full-featured C# one yet....
    >>
    >> I need one that:
    >>
    >> - Works for Mac, Windows and Unix end-of-line characters
    >> - Handles fields with end-of-line characters in the middle of it
    >> - Doesn't read the entire file into memory (files can be 100000+
    >> records)
    >> - Runs as managed code
    >>
    >> (It'd also be nice if it could read non-latin-1 character sets if
    >> necessary.)
    >>
    >> I've found a few freeware ones, but none satisfies all those
    >> requirements. I haven't been able to find a commercial one.
    >>
    >> Thanks!
    >>
    >> -Mike
    >>

    >
     
    Mike Bridge, May 11, 2004
    #3
  4. Mike Bridge

    Mike Bridge Guest

    After some further research, I found one which seems to work pretty
    well:

    http://www.falafelsoft.com/Training/Julian/Parsing_1.aspx

    Since it has its own interface for input, I was able to replace its
    native StringCharTokenizer class with my own StreamReader-based class,
    so it didn't require the whole CSV file to be loaded in memory.

    The other problem was that it didn't allow spaces in unquoted strings,
    which is pretty common in CSV files. But that's easy to fix, given
    the good explanation of the algorigthm on that page.

    -Mike



    On Tue, 11 May 2004 17:11:29 GMT, Mike Bridge <>
    wrote:

    >Can anyone suggest a good CSV parser that I can use from C#?
    >I've been using the Ostermiller CSVParser in Java, which is great, but
    >I can't find a full-featured C# one yet....
     
    Mike Bridge, May 11, 2004
    #4
  5. Mike Bridge

    clintonG Guest

    Outstanding resource. Thanks Mike.

    --
    <%= Clinton Gallagher
    A/E/C Consulting, Web Design, e-Commerce Software Development
    Wauwatosa, Milwaukee County, Wisconsin USA
    NET
    URL http://www.metromilwaukee.com/clintongallagher/



    "Mike Bridge" <> wrote in message
    news:p...
    > After some further research, I found one which seems to work pretty
    > well:
    >
    > http://www.falafelsoft.com/Training/Julian/Parsing_1.aspx
    >
    > Since it has its own interface for input, I was able to replace its
    > native StringCharTokenizer class with my own StreamReader-based class,
    > so it didn't require the whole CSV file to be loaded in memory.
    >
    > The other problem was that it didn't allow spaces in unquoted strings,
    > which is pretty common in CSV files. But that's easy to fix, given
    > the good explanation of the algorigthm on that page.
    >
    > -Mike
    >
    >
    >
    > On Tue, 11 May 2004 17:11:29 GMT, Mike Bridge <>
    > wrote:
    >
    > >Can anyone suggest a good CSV parser that I can use from C#?
    > >I've been using the Ostermiller CSVParser in Java, which is great,

    but
    > >I can't find a full-featured C# one yet....

    >
    >
     
    clintonG, May 11, 2004
    #5
    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. Michal Mikolajczyk
    Replies:
    0
    Views:
    658
    Michal Mikolajczyk
    Feb 13, 2004
  2. Skip Montanaro
    Replies:
    0
    Views:
    722
    Skip Montanaro
    Feb 13, 2004
  3. Tintin92
    Replies:
    1
    Views:
    1,716
    Andrew Thompson
    Feb 14, 2007
  4. jliu66
    Replies:
    0
    Views:
    517
    jliu66
    Oct 19, 2007
  5. sso
    Replies:
    20
    Views:
    2,675
    Martin Gregorie
    Apr 26, 2009
Loading...

Share This Page