Function to Squeeze multiple spaces in a string to one space 
Author Message
 Function to Squeeze multiple spaces in a string to one space

Option Explicit

' declare variables
Dim strMyString

strMyString = "This      is    a string   with  to many  spaces."

Wscript.Echo "Before: "
Wscript.Echo strMyString
Wscript.Echo "After: "
Wscript.Echo Squeeze(strMyString)

Function Squeeze(string)

        Dim regEx              

        ' Create regular expression.
        Set regEx = New RegExp            

        ' set the pattern to serach for
        regEx.Pattern = "(\s+)"

        ' Search for every occurence
        regEx.Global = True  

        ' Make case insensitive.
        regEx.IgnoreCase = True          

        ' Make replacement.
        Squeeze = regEx.Replace(string, " ")  

End Function



Fri, 05 Aug 2005 05:02:16 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Squeeze multiple spaces on a line into one - Without RegExp Object

2. Space Space Space Space Space Space Space

3. Space Space Space Space Space Space Space

4. Space Space Space Space Space Space Space

5. disabling the space key or removing a space from a string

6. Removing multiple spaces in a string

7. detecting one or more spaces in string

8. removing multiple space characters from a string variable

9. Removing multiple spaces from a string

10. Javascript question , Passing string with Spaces to the Function

11. Passing Strings with spaces to Functions

12. PB to erase space in string with function trim

 

 
Powered by phpBB® Forum Software