我正在处理一个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时,它会将带后缀的字符串视为另一行,我如何防止它这样做并按字面意思读取(,)?
提前谢谢。
发布于 2010-08-09 14:39:52
输入是为逗号分隔的文件设计的,请尝试使用行输入,如下所示:
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 Functionhttps://stackoverflow.com/questions/3437660
复制相似问题