vbscript 文本文件搜索具有多个字符串的一行 [英] vbscript text file search a line with multiple strings

查看:49
本文介绍了vbscript 文本文件搜索具有多个字符串的一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要在下面的 vbscript 中稍作修改...

Need small modification in the below 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 示例文件在文本文件中如下所示.

My actual mylogfile.log sample file has below in the text file.

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

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

Thanks.. in advance for your valuable time ..

推荐答案

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

这行不通.您只能为每个 Instr 调用搜索一个子字符串.

It doesn't work this way. You can only search for one substring for each Instr call.

If InStr(strLine, strSearchFor) <>0 和 (InStr(strLine, set1) 或 InStr(strLine, set2)) 然后

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

Also, there's a problem with your loop, your script will echo for each line where you can't satisfy the condition. Use a flag or something similar to keep track whether the line was found and display the error at the end.

这篇关于vbscript 文本文件搜索具有多个字符串的一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆