Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongPublic Sub ReplaceText(sFile As String, ReplaceWith As String, ReplaceTo As String) Dim inFile As Integer Dim outPath As String Dim outName As String Dim outFile As String Dim strLen As Integer Dim one_Line As String inFile = FreeFile Open sFile For Input Access Read As #inFile '打开输入文件
outPath = Space$(340) strLen = GetTempPath(340, outPath) If strLen <> 0 Then outPath = Left$(outPath, strLen)
outName = Space$(340) If GetTempFileName(outPath, "tmp", 0, outName) <> 0 Then strLen = InStr(outName, vbNullChar) - 1 If strLen > 0 Then outName = Left$(outName, strLen) outFile = FreeFile Open outName For Output Access Write As outFile
Do While Not EOF(inFile) Line Input #inFile, one_Line Print #outFile, Replace(one_Line, ReplaceWith, ReplaceTo) Loop
Close #outFile Close #inFile
Kill sFile Name outName As sFile End If End If End If End Sub
用VB6代的FSO(文件系统)吧,可以做到原本需要很多API才能做到的事. 例如: dim fs as new filesystemobject dim a as textstream //定义文本文件流 set a=fs.opentextfile(filename,forreading,false) //打开文本文件,不管他是Html or Asp文件 textbox.txt=a.readall //读全部到textbox a.close //关闭文本流抱歉,用Delphi习惯了,在语法上可能有误.
OK,那么对文本文件如何读写操作?请给出代码例子?我没有这方面的经验,手头可参考的资料几乎没有。拜托!
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongPublic Sub ReplaceText(sFile As String, ReplaceWith As String, ReplaceTo As String)
Dim inFile As Integer
Dim outPath As String
Dim outName As String
Dim outFile As String
Dim strLen As Integer
Dim one_Line As String
inFile = FreeFile
Open sFile For Input Access Read As #inFile '打开输入文件
outPath = Space$(340)
strLen = GetTempPath(340, outPath)
If strLen <> 0 Then
outPath = Left$(outPath, strLen)
outName = Space$(340)
If GetTempFileName(outPath, "tmp", 0, outName) <> 0 Then
strLen = InStr(outName, vbNullChar) - 1
If strLen > 0 Then
outName = Left$(outName, strLen)
outFile = FreeFile
Open outName For Output Access Write As outFile
Do While Not EOF(inFile)
Line Input #inFile, one_Line
Print #outFile, Replace(one_Line, ReplaceWith, ReplaceTo)
Loop
Close #outFile
Close #inFile
Kill sFile
Name outName As sFile
End If
End If
End If
End Sub
textbox中,然后查找特定字符串,在其后面插入任意字符串,并且在textbox中及时更新,就是说在textbox中显示更新后的文件内容,最后将文件保存。
你老不要敝气啊!不过我都快不行了024h(一人)
有没有发现可以直接用记录本来编辑asp或html文件,且可以保存修改结果?
icevi(按钮工厂)的意思就是把asp当作Text文件来处理,而只不过这个txt文件的扩展名是.asp而已
例如:
dim fs as new filesystemobject
dim a as textstream //定义文本文件流
set a=fs.opentextfile(filename,forreading,false)
//打开文本文件,不管他是Html or Asp文件
textbox.txt=a.readall //读全部到textbox
a.close //关闭文本流抱歉,用Delphi习惯了,在语法上可能有误.