我有一个vbscript函数需要字符串比较,其中一个/两个字符串可能包含一个通配符.不幸的是,strcomp("string1","string.*")=0对我来说不起作用,因为它正在进行比较并将.*正则表达式通配符视为文字而不是通配符.
如何比较两个字符串,其中一个和/或两个包含通配符?
功能:
Function webtableCheck(pageName, tableProperty, rowNum, colNum, checkValue)
Dim x, y, oD, oC
x = split(tableProperty,":=")
If checkValue <> "" Then
Set oD = description.Create
oD("micclass").value = "WebTable"
oD(x(0)).value = x(1)
Set oC = pageName.childobjects(oD)
y = oC(0).getcelldata(rowNum, colNum)
msgbox(y)
If y=checkValue Then
reporter.ReportEvent micPass, "WebTable Checkpoint", "The webtable checkpoint object """ & checkValue & """ was found."
Elseif **strcomp(y,checkValue,1)** = 0 Then
reporter.ReportEvent micPass, "WebTable Checkpoint", "The webtable checkpoint object """ & checkValue & """ was found, however the casing does not match."
Elseif strcomp(trim(y),trim(checkValue)) = 0 Then
reporter.ReportEvent micPass, "WebTable Checkpoint", "The webtable checkpoint object """ & checkValue & """ was found, however leading/lagging spaces not included in datatable and/or webtable cell was found."
Elseif instr(1,y,checkValue,1) Then
reporter.ReportEvent micPass, "WebTable Checkpoint", "The webtable checkpoint object """ & checkValue & """ was found., however a line break or other hidden character was found in the webtable."
Else
reporter.ReportEvent micFail, "WebTable Checkpoint", "The webtable checkpoint object """ & checkValue & """ was not found."
End If
End If
End Function
Run Code Online (Sandbox Code Playgroud)
您需要使用正则表达式,这是一个示例.
line = "this is the text to look in to, it contains the searchpattern"
Set RE = New RegExp
RE.IgnoreCase = True
RE.Pattern = "search.*tern"
If RE.Test(Line) Then WScript.echo "found"
Run Code Online (Sandbox Code Playgroud)
.*是一个正则表达式,.代表任何字符,*代表前一个或多个出现,你也可以使用.+这里+ mean表示至少有一个出现.您可以在互联网上找到关于正则表达式的众多示例和源材料,只考虑到Vbscript使用不那么标准的表单,因此请务必在搜索中包含该表单.
http://www.mikesdotnetting.com/Article/24/Regular-Expressions-and-VBScript
http://www.regular-expressions.info/vbscriptexample.html
| 归档时间: |
|
| 查看次数: |
15604 次 |
| 最近记录: |