如何使用VB6快速将文本文件加载到字符串中?
答案 0 :(得分:8)
这是在VB6中逐行加载整个文件的最快方法:
Function FileText (filename$) As String
Dim handle As Integer
handle = FreeFile
Open filename$ For Input As #handle
FileText = Input$(LOF(handle), handle)
Close #handle
End Function
答案 1 :(得分:3)
Public Function ReadFileIntoString(strFilePath As String) As String
Dim fso As New FileSystemObject
Dim ts As TextStream
Set ts = fso.OpenTextFile(strFilePath)
ReadFileIntoString = ts.ReadAll
End Function
答案 2 :(得分:-2)
以下是使用filesystemobject执行此操作的一种方法:
Public Function ReadTextFileIntoString(strPathToFile as String) as String
Dim objFSO As New FileSystemObject
Dim objTxtStream As TextStream
Dim strOutput as String
Set objTxtStream = objFSO.OpenTextFile(strPathToFile)
Do until objTxtStream.AtEndOfStream
strOutput = strOutput + objTxtStream.ReadLine
Loop
objTxtStream.Close
ReadTextFileIntoString = strOutput
End Sub