string 如何使用VB6将文本文件加载到字符串中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8208482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 01:17:43 来源:igfitidea点击:
How to load text file into string using VB6
提问by CJ7
How can I quickly load a text file into a string using VB6?
如何使用 VB6 将文本文件快速加载到字符串中?
回答by Authman Apatira
This is the fastest way to load an entire file in VB6 without doing it line by line:
这是在 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
回答by CJ7
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
回答by Nonym
Here's one way to do it using the 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