View Full Version : get rid of extra spaces

11-13-2003, 06:12 PM

I've got data like that: var1, var2, var3..........

I would like to transform it to this: var1,var2,var3. I've been trying to use the trim function but realized that it only removed the spaces at the beginning and at the end of the string... right? So I found in very usefull whammy's functions a function that does what I need but I don't know how to use it (since it's the first time I'm using one of these for something else than string manipulations). How to make them inheract?

Function RemoveExtraSpaces(ByVal str)
If IsNull(str) Then Exit Function
Dim resRegEx
Set resRegEx = New RegExp
resRegEx.Pattern = "\s+"
resRegEx.Global = True
RemoveExtraSpaces = resRegEx.Replace(str," ")
End Function

extraSpacesNotWanted=var1, var2, v ar3, va r 4, etc.....

thanx a lot for answers:)

11-13-2003, 07:45 PM
RegEx are great, but this is faster.

dim original, vacumed

original = "bla bla, bla ,bla"
vacumed = replace(original," ","")

11-13-2003, 07:48 PM
hey frenchy!!!!!! thanx a lot :thumbsup: 'hope you're doing alright with all your projects ;)

11-13-2003, 09:29 PM
However, if someone feels like answering the question as it was asked in the first place, that would be good for me to see how that would have been done ;)

Roy Sinclair
11-13-2003, 09:55 PM
newVar = RemoveExtraSpaces(extraSpacesNotWanted)

(newVar could be the same var).

11-14-2003, 09:10 AM
aaaaaaaaaaaaaaah! shame on me......:o that was that easy... thanx a lot :)

I don't know why I'm always trying funky and complicated things rather than checking what is the most simple and evident thing to do :p