Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Need CSV Parser

Reply
Thread Tools

Need CSV Parser

 
 
Mike Bridge
Guest
Posts: n/a
 
      05-11-2004
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

 
Reply With Quote
 
 
 
 
Ben Dewey
Guest
Posts: n/a
 
      05-11-2004
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/...CDriverForText


"Mike Bridge" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
Mike Bridge
Guest
Posts: n/a
 
      05-11-2004
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"
<(E-Mail Removed)> 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/...CDriverForText
>
>
>"Mike Bridge" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>> 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
>>

>


 
Reply With Quote
 
Mike Bridge
Guest
Posts: n/a
 
      05-11-2004
After some further research, I found one which seems to work pretty
well:

http://www.falafelsoft.com/Training/...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 <(E-Mail Removed)>
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....



 
Reply With Quote
 
clintonG
Guest
Posts: n/a
 
      05-11-2004
Outstanding resource. Thanks Mike.

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



"Mike Bridge" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> After some further research, I found one which seems to work pretty
> well:
>
> http://www.falafelsoft.com/Training/...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 <(E-Mail Removed)>
> 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....

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to parse a csv...... a csv that has CRLF in the fields sso Java 20 04-26-2009 11:04 AM
read and write csv file using csv module jliu66 Python 0 10-19-2007 03:12 PM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
Re: csv writerow creates double spaced excel csv files Skip Montanaro Python 0 02-13-2004 08:50 PM
csv writerow creates double spaced excel csv files Michal Mikolajczyk Python 0 02-13-2004 08:38 PM



Advertisments