中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-06 23:54
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [求助]怎样用vbs代码实现查找和写出字符串? 查看 2,168 回复 17
16 发表于 2007-12-16 14:44 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
积分 3,687
发帖 1,467
注册 2005-08-08 12:00
20年会员
UID 44210
状态 离线
Set fso = CreateObject("Scripting.FileSystemObject")

source = "a.txt"
strFind = "a,b,c,d,e,f"
strFind = Split(strFind,",")
Num = Ubound(strFind)

Set f = fso.OpenTextFile(source,1)
While not f.AtEndOfStream
strRead = f.ReadLine
For i = 0 to Num
If instr(strRead,strFind(i))>0 Then
msgbox strRead
End If
Next
Wend
f.Close

这里查找的字符区分大小写(执行的是二进制比较,具体查看instr用法)

[ Last edited by zh159 on 2007-12-16 at 02:46 PM ]
17 发表于 2007-12-17 08:12 ·  中国 福建 三明 电信
高级用户
★★
论坛上抢劫的
积分 551
发帖 246
注册 2006-09-21 12:35
19年会员
UID 63270
状态 离线
Originally posted by zh159 at 2007-12-16 14:44:
Set fso = CreateObject("Scripting.FileSystemObject")

source = "a.txt"
strFind = "a,b,c,d,e,f"
strFind = Split(strFind,",")
Num = Ubound(strFind)
...

zh159理解错我的意思了,我是说strFind的值从某一个文本中取得,不是后面跟一串,总不可能我要找50个,strFind后面打上50个变量吧!!
18 发表于 2007-12-17 10:06 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
积分 3,687
发帖 1,467
注册 2005-08-08 12:00
20年会员
UID 44210
状态 离线
Originally posted by lotus516 at 2007-12-17 08:12:

zh159理解错我的意思了,我是说strFind的值从某一个文本中取得,不是后面跟一串,总不可能我要找50个,strFind后面打上50个变量吧!!

Set fso = CreateObject("Scripting.FileSystemObject")

source = "a.txt"
target = "b.txt"

Set f = fso.OpenTextFile(source,1)
strFind = f.ReadAll
f.Close

Set f = fso.OpenTextFile(target,1)
While not f.AtEndOfStream
strRead = f.ReadLine
If instr(1,strFind,strRead,1)=0 Then
str = str & strRead & vbCrLf
End If
Wend
f.Close
msgbox str
论坛跳转: