mmatsumura Posted November 11, 2003 Posted November 11, 2003 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! :-\ Quote
*Experts* Volte Posted November 11, 2003 *Experts* Posted November 11, 2003 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. Quote
Moderators Robby Posted November 11, 2003 Moderators Posted November 11, 2003 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. Quote Visit...Bassic Software
Moderators Robby Posted November 11, 2003 Moderators Posted November 11, 2003 Volte, I wouldn't even bother, any one of these fields may contain spaces in the future. Quote Visit...Bassic Software
mmatsumura Posted November 11, 2003 Author Posted November 11, 2003 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. Quote
*Experts* Volte Posted November 11, 2003 *Experts* Posted November 11, 2003 Oh, that changes everything. Use the first 15 chars as the firstname, the next 25 as last name, and the rest as address. Quote
mmatsumura Posted November 11, 2003 Author Posted November 11, 2003 VolteFace, Thanks... Could you provide me an example? Quote
*Experts* mutant Posted November 11, 2003 *Experts* Posted November 11, 2003 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 :) Quote
*Experts* Volte Posted November 11, 2003 *Experts* Posted November 11, 2003 That example will only work if s is defined as:Dim s As String = "Mike Smith 123 Something St. Here" Quote
*Experts* mutant Posted November 11, 2003 *Experts* Posted November 11, 2003 Ah, forgot to make the spaces while I was copying the string from the first post. Thanks VolteFace. Quote
Moderators Robby Posted November 11, 2003 Moderators Posted November 11, 2003 mmatsumura, are you the one saving to or creating this text file, or is it coming from some other source beyond your control? Quote Visit...Bassic Software
mmatsumura Posted November 11, 2003 Author Posted November 11, 2003 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! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.