先读进数据,一般可以用fso。 首先引用microsoft scripting runtime Dim fso As FileSystemObject, tStream As TextStream, sBuffer As String Set fso = New FileSystemObject Set tStream = fso.OpenTextFile("e:\index.htm") sBuffer = tStream.ReadAll sBuffer = Replace(sBuffer, "src = ""images", "src = ""image") Set tStream = fso.OpenTextFile("e:\index.htm", ForWriting) tStream.Write sBuffer Set fso = Nothing Set tStream = Nothing
Private Sub Command1_Click() Open "d:\index.htm" For Input As #1 Open "d:\temp.htm" For Output As #2
Do While Not EOF(1) Line Input #1, x y = Replace(x, "src=" & Chr(34) & "images/", "src=" & Chr(34) & "image/") Print #2, y Loop
Close #1 Close #2 FileCopy "d:\temp.htm", "d:\index.htm" Kill "d:\temp.htm" MsgBox "处理完毕!" End Sub
首先引用microsoft scripting runtime
Dim fso As FileSystemObject, tStream As TextStream, sBuffer As String
Set fso = New FileSystemObject
Set tStream = fso.OpenTextFile("e:\index.htm")
sBuffer = tStream.ReadAll
sBuffer = Replace(sBuffer, "src = ""images", "src = ""image")
Set tStream = fso.OpenTextFile("e:\index.htm", ForWriting)
tStream.Write sBuffer
Set fso = Nothing
Set tStream = Nothing
Open "d:\index.htm" For Input As #1
Open "d:\temp.htm" For Output As #2
Do While Not EOF(1)
Line Input #1, x
y = Replace(x, "src=" & Chr(34) & "images/", "src=" & Chr(34) & "image/")
Print #2, y
Loop
Close #1
Close #2
FileCopy "d:\temp.htm", "d:\index.htm"
Kill "d:\temp.htm"
MsgBox "处理完毕!"
End Sub