Private Sub Form_Load() Dim b, nextline As String Open "D:\fff.txt" For Input As #1 b = "" Do Until EOF(1) Line Input #1, nextline b = b & nextline & Chr(13) & Chr(10) Loop Close #1 b = Replace(b, "$aa", "100") Open "D:\fff.txt" For Output As #1 Print #1, b Close #1 End Sub
如果文件不大(100 Mbyte 以下),还可以简单。Dim strData As StringOpen "D:\fff.txt" For Binary As #1 strData = Space(LOF(1)) Get #1, , strDatastrData = Replace(strData, "$aa", "100")Put #1, 1, strData Close #1
Dim b, nextline As String
Open "D:\fff.txt" For Input As #1
b = ""
Do Until EOF(1)
Line Input #1, nextline
b = b & nextline & Chr(13) & Chr(10)
Loop
Close #1
b = Replace(b, "$aa", "100")
Open "D:\fff.txt" For Output As #1 Print #1, b
Close #1
End Sub
如果文件不大(100 Mbyte 以下),还可以简单。Dim strData As StringOpen "D:\fff.txt" For Binary As #1
strData = Space(LOF(1))
Get #1, , strDatastrData = Replace(strData, "$aa", "100")Put #1, 1, strData
Close #1