473,470 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Seperating fields on input file

I am reading 4 variable length fields from a text file via StreamReader - a
truly slick tool - but was wondering what was the best way to seperate the
read record into its 4 fields.

I've modifed the file layout to use pipes instead of commas for the field
delimiters, but I hope there is a better method than moving the record to an
array and working it over character by character. I mean, if I have to, I
can do it, but is just seems so archiac - kind of like the Assembler I first
learned to program 30 years ago!
Nov 23 '05 #1
3 1041
Dim objReader As New System.IO.StreamReader("c:\test.txt")
Dim fields() As String
Dim line As String
Do
line = objReader.ReadLine
If Not line Is Nothing Then
fields = line.Split("|"c)
For i As Integer = 0 To fields.Length - 1
MsgBox(fields(i))
Next
End If
Loop Until line Is Nothing
objReader.Close()

hth Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"roy_ware" <ro*****@discussions.microsoft.com> schreef in bericht
news:48**********************************@microsof t.com...
I am reading 4 variable length fields from a text file via StreamReader - a truly slick tool - but was wondering what was the best way to seperate the
read record into its 4 fields.

I've modifed the file layout to use pipes instead of commas for the field
delimiters, but I hope there is a better method than moving the record to an array and working it over character by character. I mean, if I have to, I
can do it, but is just seems so archiac - kind of like the Assembler I first learned to program 30 years ago!

Nov 23 '05 #2
use the split function to get the fields in a array

regards

Michel Posseth

"roy_ware" wrote:
I am reading 4 variable length fields from a text file via StreamReader - a
truly slick tool - but was wondering what was the best way to seperate the
read record into its 4 fields.

I've modifed the file layout to use pipes instead of commas for the field
delimiters, but I hope there is a better method than moving the record to an
array and working it over character by character. I mean, if I have to, I
can do it, but is just seems so archiac - kind of like the Assembler I first
learned to program 30 years ago!

Nov 23 '05 #3
Sweet! Thank you!

"Peter Proost" wrote:
Dim objReader As New System.IO.StreamReader("c:\test.txt")
Dim fields() As String
Dim line As String
Do
line = objReader.ReadLine
If Not line Is Nothing Then
fields = line.Split("|"c)
For i As Integer = 0 To fields.Length - 1
MsgBox(fields(i))
Next
End If
Loop Until line Is Nothing
objReader.Close()

hth Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"roy_ware" <ro*****@discussions.microsoft.com> schreef in bericht
news:48**********************************@microsof t.com...
I am reading 4 variable length fields from a text file via StreamReader -

a
truly slick tool - but was wondering what was the best way to seperate the
read record into its 4 fields.

I've modifed the file layout to use pipes instead of commas for the field
delimiters, but I hope there is a better method than moving the record to

an
array and working it over character by character. I mean, if I have to, I
can do it, but is just seems so archiac - kind of like the Assembler I

first
learned to program 30 years ago!


Nov 23 '05 #4

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

Similar topics

5
by: TonyB | last post by:
Hi, I've searched the group and need more information and guidance on this issue I need to resolve next week. I work for the local school system and I am working on a way to parse a CSV file of...
1
by: John Smith | last post by:
Hi, I'm using the input File method for users to upload their files to a folder on a website, I wanted to store the filename in the database but the information that is produced from the input...
1
by: emperor-laban | last post by:
How can I add more <input type="file" /> -fields by the click of a button? The idea is that the clients should be able to upload a number of files from the same form, but I shouldn't need to know...
0
by: AnkitAsDeveloper [Ankit] | last post by:
As all we know, in order to remove cyclic includes in C++ we seperate the declarations and definitions of classs and it's member in two files Header (*.h) and source files (*.cpp). This is not a...
2
by: Joe | last post by:
Hello All: I am writing to ask for your opinions. I have a colleague who combines his code with the markup used to display the code (reckoning back to classic ASP). Here's an example of a...
5
by: jwright | last post by:
I have decided to use a struct to collect my data. The input file is comma dilineated between almost all of the fields. Here is the code I have so far and a sample input and output file. ...
4
by: jayscott1 | last post by:
What I would like to do is have the user start typing in the last name and as they were typing it would retrieve names from the database and give a drop down like autosuggest in google. That much...
0
by: clumsy_ninja | last post by:
I'm trying to create a tableless layout for a form. The following markup works as intended in Firefox and Opera, but one of IE 7's bugs ends up misplacing the floated input fields side-by-side even...
5
by: aktar | last post by:
The code below adds a file field only if no other file field is empty. The code works as expected in FF and Opera. However in IE7, it will only create one additional field. Can anyone explain...
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
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
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...
1
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...
1
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
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...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.