有一文本内容
我想找到 包含 "3" 的行
用批处理这样做
用 VBS 怎么做? 一个一个读吗?
123
adb
322
31a
121
hfh
我想找到 包含 "3" 的行
用批处理这样做
@echo off
find "3" test.txt
pause
用 VBS 怎么做? 一个一个读吗?
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
123
adb
322
31a
121
hfh
@echo off
find "3" test.txt
pause
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = True ' 设置是否区分字符大小写。
regEx.Global = True ' 设置全局可用性。
Set Matches = regEx.Execute(strng) ' 执行搜索。
For Each Match in Matches ' 遍历匹配集合。
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))
set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile("test.txt")
s=split(file.readall,vbcrlf):mys=filter(s,"3")
file.close
msgbox join(mys,vbcrlf)
option explicit '严格语法
dim found,fso,file,str
set fso=createobject("scripting.filesystemobject") '创建文件系统对象
set file=fso.opentextfile("test.txt") '打开文件,并得到文件对象
found = "" '初始化缓冲区
while not file.atendofstream '只要文件没有结束就循环
str = file.readline '读取一行内容
if instr(str,"3")>0 then '判断是否包含3
found = found & str & vbcrlf '如果包含就加入到缓冲区
end if
wend
file.close '关闭文件
msgbox found '显示结果
set fso = nothing'释放对象
set file = nothing '(不知道这句该加么?)