Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 wouldn't 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" column's 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!

 

:-\

  • *Experts*
Posted
It's 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.
  • Moderators
Posted

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.

Visit...Bassic Software
Posted

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.

  • *Experts*
Posted

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:

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 :)

Posted

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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...