Pages

Wednesday, 19 October 2011

QTP Script: Using Locate to determine if specific text exists within a string


MsgBox LocateText("www.QTPHelper.com""QTP")
MsgBox LocateText("www.QTPHelper.com""QTP.*.com")

' =============================================================
' function: LocateText
' desc :    Uses a regular expression to locate text within a string
' params :  strString is the string to perform the search on
'           strPattern is the regular expression
' returns : True if the pattern was found, False otherwise
' =============================================================
Function LocateText(strStringstrPattern)

Dim objRegEx

' create the regular expression
Set objRegEx = New RegExp 

' set the pattern 
objRegEx.Pattern = strPattern

' ignore the casing
objRegEx.IgnoreCase = True

' perform the search
LocateText = objRegEx.Test(strString)

' destroy the object
Set objRegEx = Nothing

End Function ' LocateText 

0 comments:

Post a Comment