Tab seperated files

hog

Senior Contributor
Joined
Mar 17, 2003
Messages
984
Location
UK
Can anyone give me a few pointers as to the best way to read a tab seperated text file so that I can access each field individually?

The only bumf I have on reading files details creating classes as <Serializable()> which is muddying the water.

Also I'm getting confused with all this StreamReader, FileStream, File etc??
 
Firstly doh.....should have posted this under FileIO.....

OK searching further into this site I found this link:

http://msdn.microsoft.com/library/d...adlinetopic.asp

Which allows me to read in a complete line(record) from my tab separated file but do I really have to write some code to cycle through this string to locate each tab and thus each field?

Is there not a way/method built into VB.NET to read tab files?
 
Do u mean like a ini file layout?

[Field1]
blah = hjhjhjhj
dog = white
cat = black
[Field2]
blah = jsjsss
dog = black
cat = grey
[Field2]
blah = jsjsjfgjss
dog = Pink
cat = blue
 
No the file is like this:

dog cat fish horse motorbike

Each gap is a tab character. I'm just reading in the online help about random access and creating a random access variable. This might be the answer as if I get the field sizes from the bods that produce the text file I may be in business....I think?
 
Mmm string.split looks interesting:) I was just working out on using MID() to cycle through....

I'll read on thnx
 
Ok this is what I have now but am getting wierd output??

I have a text file with these entries, (any ole guff)...

dog cat horse fish

Each separated by a tab.

This is my code:

Visual Basic:
        Dim strDelimiter As String = ControlChars.Tab

        Dim chrDelimiter As Char() = strDelimiter.ToCharArray()

        Dim strWords As String = srFile1.ReadLine

        Dim strSplit As String() = Nothing

        Dim intX As Integer

        For intX = 1 To 9

            strSplit = strWords.Split(chrDelimiter, intX)

            Dim strNewString As String

            For Each strNewString In strSplit

                MessageBox.Show(strNewString & ControlChars.CrLf)

            Next strNewString

        Next intX

Problem is this....output of each loop results in:

dog cat horse fish
dog
dog cat horse fish
dog
cat
horse fish
dog
cat
horse
fish

I know it is to do with the loops and I've tried just getting one string at a time out of the split array with no joy:(
 
Back
Top