从VB6中完美地从文本文件中提取文本的问题

问题描述 投票:0回答:1

我正在研究VB6项目,我需要从文本文件中提取纯文本。这是我用来执行此功能的代码:

Private Function FileGetText(TextFile As String) As String
Dim FileContent As String
Dim TextLine As String
Dim n As Integer
n = FreeFile
Open TextFile For Input As #n 'Open given Text File
Do Until EOF(n)
    Input #n, TextLine
    FileContent = FileContent & TextLine & vbCrLf 'Initialize text file contents line-by-line to FileContent variable
Loop
Close #n
FileGetText = FileContent 
End Function

此功能的问题在于,尽管它逐行从文件中读取文本,但是当在字符串中遇到(,)逗号时,它像在另一行中一样使用带后缀的字符串,我如何防止这样做和从字面上接受(,)?

提前感谢。

vb6 text-files
1个回答
2
投票

输入是为逗号分隔文件设计的,请尝试按以下方式使用行输入:

Private Function FileGetText(TextFile As String) As String
 Dim FileContent As String
 Dim TextLine As String
 Dim n As Integer
 n = FreeFile
 Open TextFile For Input As #n 'Open given Text File
 Do Until EOF(n)
     Line Input #n, TextLine
     FileContent = FileContent & TextLine & vbCrLf 'Initialize text file contents line-by-line to FileContent variable
 Loop
 Close #n
 FileGetText = FileContent 
End Function
© www.soinside.com 2019 - 2024. All rights reserved.