Thursday, December 22, 2011

VBScript : removeExtraSpaces()

This function uses VBScript RegExp to find and remove unwanted/superflous spaces in a string.
Function removeExtraSpaces(str)
 Dim res
 Dim re : set re = New RegExp
 re.Global = True
 re.Pattern = "\s+"
 removeExtraSpaces = re.Replace(str," ")
End Function

'== EXAMPLE ==
myString = " A   lot of   space"
wscript.echo removeExtraSpaces(myString) '-> A lot of space

'

No comments:

Post a Comment