VB怎么查找并替换字符串
我有aa.txt和bb.txt两个文本aa内容:bbabanbang帮bu不bb的是:b2ba1ban1name代表着aa里的文字,当name为空的时候就在bb里查找和n...
我有aa.txt和bb.txt两个文本 aa内容: b ba ban bang 帮 bu 不 bb的是: b 2 ba 1 ban 1 name代表着aa里的文字,当name为空的时候就在bb里查找和name相对应的哪一行并替换。比如当name = b 的时候name没有文字为空,那就在bb里查找b的哪一行也就是b 2这行替换aa里的b
展开
1个回答
展开全部
我默认路径为d:\aa.txt,d:\bb.txt,请自己修改。建Command1.代码如下。
==================
Option
Explicit
Private
Sub
Command1_Click()
Dim
aa
As
String,
bb
As
String
Open
"d:\aa.txt"
For
Input
As
1
Open
"d:\bb.txt"
For
Input
As
2
Open
"d:\cc.txt"
For
Output
As
3
Do
Until
EOF(1)
Line
Input
#1,
aa
If
EOF(2)
Then
Print
#3,
aa
Else
Line
Input
#2,
bb:
Print
#3,
IIf(Right(aa,
1)
=
"
",
bb,
aa)
Loop
Close
Kill
"d:\aa.txt"
Name
"d:\cc.txt"
As
"d:\aa.txt"
MsgBox
"替换完毕。"
End
Sub
==================
Option
Explicit
Private
Sub
Command1_Click()
Dim
aa
As
String,
bb
As
String
Open
"d:\aa.txt"
For
Input
As
1
Open
"d:\bb.txt"
For
Input
As
2
Open
"d:\cc.txt"
For
Output
As
3
Do
Until
EOF(1)
Line
Input
#1,
aa
If
EOF(2)
Then
#3,
aa
Else
Line
Input
#2,
bb:
#3,
IIf(Right(aa,
1)
=
"
",
bb,
aa)
Loop
Close
Kill
"d:\aa.txt"
Name
"d:\cc.txt"
As
"d:\aa.txt"
MsgBox
"替换完毕。"
End
Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询