如何使用VB6将文本文件加载到字符串中

发布于 2024-12-17 07:40:58 字数 31 浏览 3 评论 0原文

如何使用 VB6 快速将文本文件加载到字符串中?

How can I quickly load a text file into a string using VB6?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

゛清羽墨安 2024-12-24 07:40:58

这是在 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

This is the fastest way to load an entire file in VB6 without doing it line by line:

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
夜无邪 2024-12-24 07:40:58
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 
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 
爱殇璃 2024-12-24 07:40:58

这是使用文件系统对象执行此操作的一种方法:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文