Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stripping multiple blank spaces from a text box??? 1

Status
Not open for further replies.

ftpdoo

Programmer
Aug 9, 2001
202
GB
Hi,

I have a text box called "txtText" which contains string data. ie (Bla Bla Bla Bla)

If more than one space occurs between these words in the text box I want to take them out and replace them with a single space..

(ie If more than one space occurs between two words then strip away the excess spaces and leave a single space)

Any Idea's??
Thnx,
Jonathan
 
Hi Jonathan!

You can use this code:

Dim lngStartPosition As Long
Dim lngSpacePosition As Long
Dim strTextString As String

strTextString = Trim(txtText)
lngStartPosition = 1
lngSpacePostion = InStr(strTextString, " ")
Do While lngSpacePosition <> 0
If Mid(strTextString, lngSpacePosition+1, 1) = &quot; &quot; Then
strTextString = Left(strTextString, lngSpacePosition) & Mid(strTextString, lngSpacePosition + 2)
Else
lngStartPosition = lngSpacePosition + 1
End If
lngSpacePosition = InStr(lngStartPosition, strTextString, &quot; &quot;)
Loop

txtText = strTextString

I haven't tested this code but it should work

hth
Jeff Bridgham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top