'Locate Method
' Using Locate to determine if specific text exists within a string.
MsgBox LocateText("http://blog.youkuaiyun.com/xuyubotest", "xuyubotest")
MsgBox LocateText("http://blog.youkuaiyun.com/xuyubotest", "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(strString, strPattern)
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
' Using Locate to determine if specific text exists within a string.
MsgBox LocateText("http://blog.youkuaiyun.com/xuyubotest", "xuyubotest")
MsgBox LocateText("http://blog.youkuaiyun.com/xuyubotest", "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(strString, strPattern)
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
本文介绍了一个使用正则表达式在字符串中查找特定模式的函数。通过两个示例演示了如何利用该函数来判断指定的文本是否存在于给定的字符串中。此方法适用于不区分大小写的搜索。
3万+

被折叠的 条评论
为什么被折叠?



