QA automation with QTP/UFT – function to remove all special characters from a string

Hello and happy Friday! I wanted to cover a great function that can be used to rid your string of special characters.


Function fun_removeSpecialCharacters (pstrToClean)
    Dim objRegExp, outputStr
    Set objRegExp = New Regexp
    
    objRegExp.IgnoreCase = True
    objRegExp.Global = True
    objRegExp.Pattern = "[()?*"",\\<>&#~%{}+_.@:\/!;]+"
    outputStr = objRegExp.Replace(strToClean, "")
    
    objRegExp.Pattern = "\-+"
    outputStr = objRegExp.Replace(outputStr, "")
    
    fn_removeSpecialCharacters = outputStr
End Function


 

To use the function, simply call it with the string from which you want to remove the special characters:

strExample = "73282*&923()"

MsgBox fn_removeSpecialCharacters(strExample)

 

Great right? Please leave your comments and feedback below. I appreciate all of your support!

Pin It on Pinterest

Clef two-factor authentication