VB怎么在文本查找字符串并替换相应的内容

有一个文本1.txt,内容为
q = 1111
w = 2222
e = 3333
r = 4444
t = 5555
..........
text1.text输入 qwtooreedd
text2.text输出 11112222too444433333333dd
关键字在文本就替换,不存在就不处理。

第1个回答  推荐于2016-06-14
Private Sub Command1_Click()
Dim a(), b(), c() As String, n, s, i
n = 0
Open "c:\1.txt" For Input As #1
While Not EOF(1)
Line Input #1, s
c = Split(s, "=")
If UBound(c) = 1 Then
ReDim Preserve a(n), b(n)
a(n) = Trim(c(0))
b(n) = Trim(c(1))
n = n + 1
End If
Wend
Close #1
Text2 = Text1
For i = 0 To n - 1
Text2 = Replace(Text2, a(i), b(i))
Next
End Sub本回答被提问者采纳
相似回答