如何读出 index.htm 文件, 找到 src="images/2.gif" 后,把所有images 串替换 image 并写回文件

解决方案 »

  1.   

    文件已经在你手里了吗,是的话就Replace("src=" & chr(34) & "images/","src=" & chr(34) & "image/"),
      

  2.   

    先读进数据,一般可以用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
      

  3.   

    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