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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert 2 blanks to 1

Status
Not open for further replies.

projecttoday

Programmer
Feb 28, 2004
208
0
0
US
Is there any way of converting multiple blanks in a string between words to just one blank?
 
John<blank>Q.<blank><blank>Smith
becomes
John<blank>Q.<blank>Smith

Little<blank>Rock,<blank><blank>Arkansas
becomes
Little<blank>Rock,<blank>Arkansas
 
How are ya projecttoday . . .

Try the following function:
Code:
[blue]Public Function TrimSpaces(ByVal Dat As String) As String
   
   Do Until InStr(1, Dat, "  ") = 0
      Dat = Replace(Dat, "  ", " ")
   Loop
   
   TrimSpaces = Dat
      
End Function[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Or another way:
Code:
Public Function ReplaceSpaces(strInput As String) As String
Dim re As Object

Set re = CreateObject("VBScript.RegExp")

With re
    .Global = True
    .MultiLine = True
    .IgnoreCase = True
    .Pattern = "\s{2,}"
    ReplaceSpaces = .Replace(strInput, " ")
End With

Set re = Nothing
End Function
Hope this helps

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top