473,386 Members | 1,702 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,386 software developers and data experts.

Reading CSV files

RD
Need to read a comma separated values file, line by line and extract each
value from each line. There may be variable number of values in each of the
lines.

Anyone know of any sample code to do this?
Used to be easy in vb6 , oh well!

Thanks for any help,

Bob
Nov 20 '05 #1
2 1343
On Wed, 17 Dec 2003 17:28:05 -0500, RD wrote:
Need to read a comma separated values file, line by line and extract each
value from each line. There may be variable number of values in each of the
lines.

Anyone know of any sample code to do this?
Used to be easy in vb6 , oh well!

Thanks for any help,

Bob


It's easy in .Net too. Look at the classes in the System.IO namespace.
Here's a sample from memory (may have typos):

'\\\\\
Imports System.IO

Public Sub ReadCSVFile(fname As String)

Dim sr As StreamReader = File.OpenText(fname)

'Array to hold all of the comma delimited items
Dim aTokens() As String

Do While sr.Peek() >= 0
aTokens = sr.ReadLine().Split(',')
For x As Integer = 0 to aTokens.Length - 1
'Do something here with the token
Console.WriteLine(aTokens(x))
Next
Loop

sr.Close()

End Sub
'/////
--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #2
RD
Thanks Chris
"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:xj******************************@40tude.net.. .
On Wed, 17 Dec 2003 17:28:05 -0500, RD wrote:
Need to read a comma separated values file, line by line and extract each value from each line. There may be variable number of values in each of the lines.

Anyone know of any sample code to do this?
Used to be easy in vb6 , oh well!

Thanks for any help,

Bob


It's easy in .Net too. Look at the classes in the System.IO namespace.
Here's a sample from memory (may have typos):

'\\\\\
Imports System.IO

Public Sub ReadCSVFile(fname As String)

Dim sr As StreamReader = File.OpenText(fname)

'Array to hold all of the comma delimited items
Dim aTokens() As String

Do While sr.Peek() >= 0
aTokens = sr.ReadLine().Split(',')
For x As Integer = 0 to aTokens.Length - 1
'Do something here with the token
Console.WriteLine(aTokens(x))
Next
Loop

sr.Close()

End Sub
'/////
--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #3

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

Similar topics

3
by: Olivier Maurice | last post by:
Hi all, I suppose some of you know the program Redmon (type redmon in google, first result). This neat little tool allows to hook up any functionality to a printer by putting the file printed...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
6
by: Rajorshi Biswas | last post by:
Hi folks, Suppose I have a large (1 GB) text file which I want to read in reverse. The number of characters I want to read at a time is insignificant. I'm confused as to how best to do it. Upon...
2
by: nnimod | last post by:
Hi. I'm having trouble reading some unicode files. Basically, I have to parse certain files. Some of those files are being input in Japanese, Chinese etc. The easiest way, I figured, to distinguish...
7
by: jccorreu | last post by:
I've got to read info from multiple files that will be given to me. I know the format and what the data is. The thing is each time we run the program we may be using a differnt number of files,...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
10
by: Tyler | last post by:
Hello All: After trying to find an open source alternative to Matlab (or IDL), I am currently getting acquainted with Python and, in particular SciPy, NumPy, and Matplotlib. While I await the...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
4
by: Miner Jeff | last post by:
Hello, I have a basic question about reading files. I have several data files where the filenames are identical except for a short (3 character) prefix. I inherited this code and the person who...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.