Text File Input

mmatsumura

Member
Joined
Sep 8, 2003
Messages
12
For the past few days I have been trying to design a simple VB.NET application that would allow me to read-in a text (.txt) file. While surfing around I have not been able to find something that would work, given the structure of the following file:

FName LName Address City
Mike Smith 123 Something St. Here
David Jones 12-34 Their Ave. Someplace
Arlene Wife 66 Our St. Who Knows
Al LongLastName 123 His Place Who Cares

Where I am really running into a tough time is that the space between each column is exactly that - spaces. If the space was a tab, comma, specific charater, etc., I wouldnt have a problem. If the length of each columns text was the same for each line, no problem. The other thing is that the "Address" columns text does have spaces to seperate the house number from the street name.

So, what could I do? ANY assistance would be greatly appriciated!


In advance, Thanks!

:-\
 
Its not totally fool-proof, but you could simply take the first word (up to the first space) as the first name, the second word (first space to second space) as the second name, and the rest as the address. This will only work in no First or Last names have spaces with-in them.
 
There not much you can do, it is very difficult to work with a Space delimited file, as you said the Address may have spaces.

Whoever is loading the file should be advised to include a useful delimiter.
 
Thanks to all!

I should have mentioned... the number of spaces between each column varies. For example, the FName column length is 15; LName is 25, etc. Sorry for not having said that.
 
Oh, that changes everything. Use the first 15 chars as the firstname, the next 25 as last name, and the rest as address.
 
If im understanding your problem correctly, then reading the line of text into a string, and then using the SubString methd of the string should work. For example use substring to retrieve first 15 characters, and then start at 16 and get 25 characters:
Code:
Dim s As String = "Mike Smith 123 Something St. Here"
Dim first As String = s.Substring(0, 15) get first 15 characters from the string
If I didnt get what you are trying to do correct me :)
 
That example will only work if s is defined as:
Code:
Dim s As String = "Mike           Smith          123 Something St. Here"
 
mmatsumura, are you the one saving to or creating this text file, or is it coming from some other source beyond your control?
 
Robby,

Thanks... What I am trying to do is create this file from a .txt file. Should I be able to pull this off, my plan is to export append data from another .txt file followed by exporting it.

Hope this answers your question. (If not please let me know.)

Should you have one and wish, provide me complete VB.NET code.


Thanks!
 
Back
Top