开发者

Problem extracting text from text file perfectly in VB6

开发者 https://www.devze.com 2023-01-10 14:32 出处:网络
I am working on a VB6 project and I need to extract plain text from a text file. Here is code of the function I used to do that:

I am working on a VB6 project and I need to extract plain text from a text file. Here is code of the function I used to do that:

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

The problem with this function is that, though it reads text from file line by line, but 开发者_StackOverflow社区when encounters (,) coma in the string, it takes the suffixed string as in another line, how can I prevent it from doing so and take (,) literally?

Thanks in advance.


Input is designed for a comma delimited file, try using Line Input as follows:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消