2012-10-17 20 views
0

需要在下面的VBScript小改...VBScript中的文本文件搜索与多串线

Const ForReading = 1 

Dim strSearchFor, set1, set2 
strSearchFor = "10/17/2012" 
set1= app1 

set2 =app2 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objTextFile = objFSO.OpenTextFile("mylogfile.log", ForReading) 

do until objTextFile.AtEndOfStream 
    strLine = objTextFile.ReadLine() 

    If InStr(strLine, strSearchFor and set1 or set2) <> 0 then 

Wscript.Echo "we found current date with app1 or current date with app2" 
    Else 
     Wscript.Echo "We did not found current date" 
    End If 
loop 
objTextFile.Close 

我的实际mylogfile.log示例文件下方的文本文件。

working on 10/17/2012 starting something ending 
closing on started app1 
working on 10/17/2012 starting something app1 
working on 10/17/2012 starting something app2 
closing on 10/17/2012 starting something ending 

谢谢..提前为您宝贵的时间..

回答

0

If InStr(strLine, strSearchFor and set1 or set2) <> 0 then

它不以这种方式工作。您只能搜索每个Instr呼叫的一个子字符串。

If InStr(strLine, strSearchFor) <> 0 and (InStr(strLine, set1) or InStr(strLine, set2)) then

此外,还有与你的循环有问题,你的脚本会响应的每一行,你不能满足该条件。使用标志或类似的东西来跟踪行是否被找到,并在最后显示错误。

+0

badea Bhai谢谢.. – user1751790