|
-
Jan 28th, 2000, 04:45 AM
#1
Thread Starter
Hyperactive Member
I need to read a linux text file in VB. THe problem is that Linux ends a line with hex(0A) and dos reads an end of line as hex(0A 0D). Is the any way in vb that I can switch this character. If I don't, it will read the entire file as 1 line. Since I have to seperate the lines this doesn't help me. I use perl right now but I'd like to have it all in one program.
As an option, is there a way I can run Perl in VB?
-
Jan 30th, 2000, 09:26 PM
#2
Frenzied Member
this should read the file into an array of strings
(I haven't tested it though!)
Code:
Private Sub Command1_Click()
Dim fnum As Long
Dim WholeFile As String
Dim char As String
Dim lines() As String
Dim i As Integer
Dim charPos As Integer
Open "TESTFILE" For Binary As fnum ' Open file.
WholeFile = Space(LOF(fnum))
Get fnum, , WholeFile
Close fnum
charPos = InStr(WholeFile, Chr(10))
While charPos <> 0
charPos = InStr(WholeFile, Chr(10))
ReDim Preserve lines(i + 1)
lines(i) = Left(WholeFile, charPos - 1)
'trim the text
WholeFile = Mid(WholeFile, charPos + 1)
i = i + 1
Wend
End Sub
------------------
Mark Sreeves
Analyst Programmer
[email protected]
A BMW Group Company
-
Jan 30th, 2000, 09:28 PM
#3
Frenzied Member
this should read the file into an array of strings
(I haven't tested it though!)
Code:
Private Sub Command1_Click()
Dim fnum As Long
Dim WholeFile As String
Dim char As String
Dim lines() As String
Dim i As Integer
Dim charPos As Integer
Open "TESTFILE" For Binary As fnum ' Open file.
WholeFile = Space(LOF(fnum))
Get fnum, , WholeFile
Close fnum
charPos = InStr(WholeFile, Chr(10))
While charPos <> 0
charPos = InStr(WholeFile, Chr(10))
ReDim Preserve lines(i + 1)
lines(i) = Left(WholeFile, charPos - 1)
'trim the text
WholeFile = Mid(WholeFile, charPos + 1)
i = i + 1
Wend
End Sub
------------------
Mark Sreeves
Analyst Programmer
[email protected]
A BMW Group Company
-
Jan 30th, 2000, 09:34 PM
#4
Thread Starter
Hyperactive Member
I'll try that. Thanks. What exactly does it do? Does it read the whole file into a string and then divide it or does it take a piece at a time?
-
Jan 30th, 2000, 10:11 PM
#5
Thread Starter
Hyperactive Member
It works great. I just dump lines() back into another file. I'm still wondering whether it dumps the entire file into memory (the string) or whether it only takes pieces of it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|