Parse a CSV file in C#?

G

Guest

Hi,

I have a CSV file with some data (7,500 rows , 18 columns)

How can I parse this file in C#?

Can I programmatically save the file as an Excel Workbook and then parse the
file using the Excel Namespace Methods available?

Or can I programmatically save the CSV file as an XML file and then parse
the XML?

Any advice is much appreciated.

Thanks.
 
P

Peter Rilling

Open with a StreamReader, read each line, then do a String.Split on the
commas. Repeat for each line.
 
G

Guest

Open with a StreamReader, read each line, then do a String.Split on the
commas. Repeat for each line.

That doesn't work for all CSV files, though. The data in a data row may
contain line breaks, so a data row may span over any number of lines.

Fields that contain line breaks are generally enclosed in quotes. A quoted
field may also contain double quotes to represent quotes in the data.

Sadly there exists no independent standard for the CSV file format. Most CSV
files are not even comma separated at all, but semicolon separated.

The format that Microsoft Office uses seems to be a de-facto standard, but
as it's not a real standard, your CSV files may actually look rather
differently.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top