473,769 Members | 3,305 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.22334 4
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 54895
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.22334 4
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.Ole Db 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.Odb c namespace to access the file using ODBC drivers.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Markus Stoeger" <sp******@gmx.a t> wrote in message
news:en******** ******@tk2msftn gp13.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.22334 4
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.c om> wrote in
message news:O4******** ******@tk2msftn gp13.phx.gbl...
That's not necessarily true.

You can use the JET 4.0 OLE DB provider with the classes in the
System.Data.Ole Db 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.Odb c namespace to access the file using ODBC drivers.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Markus Stoeger" <sp******@gmx.a t> wrote in message
news:en******** ******@tk2msftn gp13.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.22334 4
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
3469
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 record contains a header line for describing the sequence that begins with a '>' (right-angle bracket) followed by lines that contain the actual sequence data. Three example FASTA records are below: >CW127_A01...
12
1611
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
14845
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 software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
47
4544
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 company and this is a big decision for us(!) It's not just the money it's committing to an new version of Access!
8
3184
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 basically entitled to us to just about every .Net development tool you can imagine. I cant even begin to mention them. To begin with, my background is not that of a programmer, but a systems engineer and the closest I have come to "programming"...
17
8042
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 read or modify this string so I don't want to store it in an INI / Text file or in registery. Can someone please tell me the best practice for this. Thanks Mike
34
2814
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 happens if the number of lines is huge? I have a very big file (4GB) I want to read in, but I'm sure there must be some limitation to readlines and I'd like to know how it is handled by python. I am using it like this:
11
1928
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 into it by typing a name, duration, description. What is most common, best practice: to store the DVD's entrys in a flatfile, in a database (what database) or is there another solution.
21
8090
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
2765
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 to find the best way to do it but I am just not experienced enough with this sort of thing to make the best decision, so any advice would be great. The data is on a number of different nested tables with in the HTML, and on a number of different...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.