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

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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
 
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.
 
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
 
Back
Top