What's the best way to read a .CSV file in C#

G

Guest

I have a .CSV file that I need to read, reformat, and write back out as a TAB
delimited file. I can't use a slick utility such as DTS, because I have a
lot of tweaking I need to do on the data before it can be output. The data
is true .CSV fasion, in other words, a record may look as follows:
1.23,"this is a ""special"" field",2,"brian's test","one,two,three",45.223344
There are embeded quotes, apostrophes, and commas in the data. This makes
something like Split() out of the question. Is there a method to read a .CSV
and just refer to the columns as an array?
 
M

Markus Stoeger

Brian said:
I have a .CSV file that I need to read, reformat, and write back out as a TAB
delimited file. I can't use a slick utility such as DTS, because I have a
lot of tweaking I need to do on the data before it can be output. The data
is true .CSV fasion, in other words, a record may look as follows:
1.23,"this is a ""special"" field",2,"brian's test","one,two,three",45.223344
There are embeded quotes, apostrophes, and commas in the data. This makes
something like Split() out of the question. Is there a method to read a .CSV
and just refer to the columns as an array?

afaik there is no such thing built into the framework.

codeproject.com always is a good start. Maybe this will work for you?
http://www.codeproject.com/cs/database/CsvReader.asp

Max
 
N

Nicholas Paldino [.NET/C# MVP]

That's not necessarily true.

You can use the JET 4.0 OLE DB provider with the classes in the
System.Data.OleDb namespace to access the comma delimited text file (using a
DataSet/DataTable).

Or you could use Microsoft Text Driver for ODBC with the classes in the
System.Data.Odbc namespace to access the file using ODBC drivers.

Hope this helps.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


In addition you could use the provider from opennetcf (www.opennetcf.org )
It's good fast and you have the source code so you can customize it.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Nicholas Paldino said:
That's not necessarily true.

You can use the JET 4.0 OLE DB provider with the classes in the
System.Data.OleDb namespace to access the comma delimited text file (using
a DataSet/DataTable).

Or you could use Microsoft Text Driver for ODBC with the classes in the
System.Data.Odbc namespace to access the file using ODBC drivers.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Markus Stoeger said:
afaik there is no such thing built into the framework.

codeproject.com always is a good start. Maybe this will work for you?
http://www.codeproject.com/cs/database/CsvReader.asp

Max
 

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

Top