473,513 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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?
Nov 17 '05 #1
3 54876
Brian Kitt wrote:
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
Nov 17 '05 #2
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]
- mv*@spam.guard.caspershouse.com

"Markus Stoeger" <sp******@gmx.at> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
Brian Kitt wrote:
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

Nov 17 '05 #3
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:O4**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Markus Stoeger" <sp******@gmx.at> wrote in message
news:en**************@tk2msftngp13.phx.gbl...
Brian Kitt wrote:
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


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
3435
by: Chris Lasher | last post by:
Hello, I have a rather large (100+ MB) FASTA file from which I need to access records in a random order. The FASTA format is a standard format for storing molecular biological sequences. Each...
12
1588
by: python | last post by:
In a file there can be several dictionaries like this {Key11: Value11 Key12: Value12 Key13: Value13, .... .... Key1n:Value1n} {Key21: Value21 Key22: Value22 Key23: Value23,
125
14544
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
47
4482
by: ship | last post by:
Hi We need some advice: We are thinking of upgrading our Access database from Access 2000 to Access 2004. How stable is MS Office 2003? (particularly Access 2003). We are just a small...
8
3122
by: Midnight Java Junkie | last post by:
Dear Colleagues: I feel that the dumbest questions are those that are never asked. I have been given the opportunity to get into .NET. Our organization has a subscription with Microsoft that...
17
7999
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
34
2759
by: Ross Reyes | last post by:
HI - Sorry for maybe a too simple a question but I googled and also checked my reference O'Reilly Learning Python book and I did not find a satisfactory answer. When I use readlines, what...
11
1894
by: Marcel | last post by:
Hello all, I am a C++ beginner. I would like to know where and how a C++ application stores it's data. For example, imagine an application to manage your DVD collection. DVD can be enterd...
21
8029
by: Owen Zhang | last post by:
What is the best way to implement "tail -f" in C or C++ and higher performance compared to either unix shell command "tail -f" or perl File::Tail ? Any suggestion appreciated. Thanks.
4
2752
by: ink | last post by:
Hi all, I am trying to pull some financial data off of an HTML web page so that I can store it in a Database for Sorting and filtering. I have been thinking about this for some time and trying...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.