回答正确+100分 vb 替换字符串问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 12:23:46
我想把源文件中的 字符串进行逐行替换
例如:$1 abd-bcdgsaf ti@sfsfg
$2 sfsgeuin
所有$替换为a
所有ti@替换为空,并且在作此替换的行最后一个字符后加上oti
替换结果为
a1 abd-bcdgsaf sfsfgoti
a2 sfsgeuin
谢谢大家 楼主什么都不会。。。 0基础开始编程序好费劲啊

Private Sub Foo(lpText As String) '传入原字符串
Dim temp() As String, i As Integer, result As String
temp = Split(lpText, vbCrLf) '按回车换行分开
For i = 0 To UBound(temp) '对于每行
If InStr(0, temp(i), "ti@") > 0 Then temp(i) = temp(i) & "oti" '如果有"ti@",则在行末加上"oti"
temp(i) = Replace(temp(i), "$", "a") '把所有"$"替换为"a"
temp(i) = Replace(temp(i), "ti@", vbNullString) '把所有"ti@"替换为空字符串
result = resutl & temp(i) & vbCrLf '把这行合并到其它已经处理的行
temp(i) = vbNullString '释放内存空间
Next i '循环
lpText = result '把结果传回lpText引用
End Sub

Private Sub Command1_Click()
Dim s As String
Dim str As String

Open "c:\1.txt" For Input As #1
Do While (Not EOF(1))
Line Input #1, s
s = Replace(s, "$", "a")
If InStr(1, s, "ti@") <> 0 Then<