Need CSV Parser

M

Mike Bridge

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
 
M

Mike Bridge

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
 
M

Mike Bridge

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top