473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 54868
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
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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,...

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.