Saturday 29 August 2015

Replace multiple spaces with single space using RegExp..

str="Removing      multiple    (multiple     spaces here    )    spaces      with    single (single space here) space   character."&_
"       m done  !   !       &"

Call replaceMultiSpace(str)
Function replaceMultiSpace(strIO)
    replaceMultiSpace=""
    If strIO="" Then
        MsgBox "Invalid input string.."
        Exit Function
    End If
    Set rg=New RegExp
    rg.Global=True
    rg.IgnoreCase= True
    rg.Pattern= "\s{2,}"
     output=rg.Replace(strIO, " ")
     If output<>"" Then     
        replaceMultiSpace=output
         MsgBox "Refined Output: "& replaceMultiSpace
     End If    
     Set rg=Nothing
 End Function

No comments:

Post a Comment