参考如下: Option Explicit '引用Microsoft Scripting Runtime Private Sub Form_Load() Dim oFSO As FileSystemObject Dim oTextStream As TextStream Dim oFirstLine As String Dim i, LineNum As Integer Set oFSO = CreateObject("scripting.filesystemobject") '以下为删除相关行 oTextStream.Close Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForReading, False, TristateFalse) Dim str As String '存内容 dim TempStr as string str = oTextStream.ReadLine '读第一行 Do While oTextStream.AtEndOfLine <> True TempStr= oTextStream.ReadLine if instr(tempstr,"杭州") <0 then str = str & vbcrlf & oTextStream.ReadLine end if Loop LineNum = i oTextStream.Close Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForWriting, False, TristateFalse) oTextStream.Write str '重写文件 oTextStream.Close Set oFSO = Nothing End Sub
Option Explicit
'引用Microsoft Scripting Runtime
Private Sub Form_Load()
Dim oFSO As FileSystemObject
Dim oTextStream As TextStream
Dim oFirstLine As String
Dim i, LineNum As Integer
Set oFSO = CreateObject("scripting.filesystemobject")
'以下为删除相关行
oTextStream.Close
Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForReading, False, TristateFalse)
Dim str As String '存内容
dim TempStr as string
str = oTextStream.ReadLine '读第一行
Do While oTextStream.AtEndOfLine <> True
TempStr= oTextStream.ReadLine
if instr(tempstr,"杭州") <0 then
str = str & vbcrlf & oTextStream.ReadLine
end if
Loop
LineNum = i
oTextStream.Close
Set oTextStream = oFSO.OpenTextFile("c:\aa.txt", ForWriting, False, TristateFalse)
oTextStream.Write str '重写文件
oTextStream.Close
Set oFSO = Nothing
End Sub