...

View Full Version : get rid of extra spaces



jeskel
11-13-2003, 05:12 PM
Hi,

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:)

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


dim original, vacumed

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

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

jeskel
11-13-2003, 08: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, 08:55 PM
newVar = RemoveExtraSpaces(extraSpacesNotWanted)

(newVar could be the same var).

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

<edit>
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
</edit>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum