我正在研究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
这个函数的问题在于,尽管它逐行从文件中读取文本,但是当在字符串中遇到(,)coma时,它会将后缀字符串视为另一行,我该如何阻止它这样做并采取(,)字面意思??
先谢谢.....: - )
答案 0 :(得分:2)
输入是为逗号分隔文件设计的,请尝试使用Line Input,如下所示:
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