vb删除txt指定内容

比如有一个1.txt文件。内容如下:
12324
346556ffgdfg
基本原理d
123
万无一失tr
45654发edftrt
123
sdfgsdgsdg
......
后面还有若干行
现在想用VB写个程序 在text1输入123。当按下按钮后,程序会删除文件内由text1指定的字符123这样的字符。也就是说会把文件里的第4行和第7行的123删除了。(要注意是虽然文件里的第一行的12324里有123这样的字符,但是该行内容包含了其它字符。所以不能删除),请高高手帮帮忙,给你写下代码。急哦!

Dim FileRead As Integer
Dim FileWrite As Integer
Dim Str As String

FileRead = FreeFile
Open "C:\1.txt" For Input As FileRead

FileWrite = FreeFile
Open "C:\Tmp.txt" For Output As FileWrite

Do While Not EOF(FileRead)
Input #FileRead, Str
If Str <> Text1.Text Then
Print #FileWrite, Str
End If
Loop

Close FileRead
Close FileWrite

Kill "C:\1.txt"
Name "C:\Tmp.txt" As "C:\1.txt"
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-03-04
直接用正则的replace方法比较快 我空间里有正则的一些资料 呵呵
相似回答