首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在VB6中从文本文件中提取文本时出现问题

在VB6中从文本文件中提取文本时出现问题
EN

Stack Overflow用户
提问于 2010-08-09 14:02:30
回答 1查看 550关注 0票数 0

我正在处理一个VB6项目,我需要从文本文件中提取纯文本。下面是我用来做这件事的函数代码:

代码语言:javascript
复制
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时,它会将带后缀的字符串视为另一行,我如何防止它这样做并按字面意思读取(,)?

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-09 14:39:52

输入是为逗号分隔的文件设计的,请尝试使用行输入,如下所示:

代码语言:javascript
复制
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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3437660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档