|
-
November 27th, 1999, 10:29 AM
#1
space delimited text file
I am working on a subroutine to convert space-delimited files to semicolon-delimited files. Right now the file looks something like this:
Adam Smith 45 Cherry St. 789-0098
Susan Sarandon 123 123rd Avenue 555-5555
Walter Matthau 54 Hollywood Blvd. 123-4567
Right now I am using the code
[vbcode]
Open CommonDialog1.Filename For Input as #File1
Line Input #File1, strText
Open CommonDialog2.Filename For Output as #File2
Print #File2, Texto
Obviously all this does is copy the file but unfortunately that is about the extent of my VB experience. I need a subroutine that will read the file, replace the white spaces between columns with a ";" and also return the column length (e.g. the number of spaces between the A of Adam Smith and the first number of his phone number).
any suggestions will be GREATLY appreciated!
Thanks,
Andrew
-
November 28th, 1999, 12:47 AM
#2
Re: space delimited text file
Andrew,
The following function will replace all " " with ";"
Open CommonDialog1.Filename For Input as #File1
Line Input #File1, strText
strText = Replace(strText, " ", ";")
There is documentation on MSDN to explain more.
The part of counting the replacements could be done like the following:
Dim I as Long
Dim J as Long
I = 1
Do Until I = 0
I = InStr(I + 1, strText, ";")
If I <> 0 Then
J = I
End If
Loop
Crude but it works in a sticky situation.
Allen Noakes
VB Programmer/Analyst
Dames & Moore
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|