Seperating fields on input file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
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
 
use the split function to get the fields in a array

regards

Michel Posseth
 
Sweet! Thank you!

Peter Proost said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top