MsgBox ReplaceText("Automating with QTP is rubbish.", "rubbish.", "great!")
MsgBox ReplaceText("QTP is a great automation tool but I can't use it","but.*","!")
' =============================================================
' function: ReplaceText
' desc : Uses a regular expression to replace text within a string
' params : strString is the string to perform the replacement on
' strPattern is the regular expression
' strReplacement is the replacement string
' returns : The finished string
' =============================================================
Function ReplaceText(strString, strPattern, strReplacement)
Dim objRegEx
' create the regular expression
Set objRegEx = New RegExp
' set the pattern
objRegEx.Pattern = strPattern
' ignore the casing
objRegEx.IgnoreCase = True
' make the replacement
ReplaceText = objRegEx.Replace(strString, strReplacement)
' destroy the object
Set objRegEx = Nothing
End Function ' ReplaceText
Wednesday, 19 October 2011
QTP Script: Using the replace method to find and replace text in a string
21:17
No comments
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment