If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Parse the string, reading and wrting file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-29-04, 14:27
finditout finditout is offline
Registered User
 
Join Date: Jan 2004
Posts: 3
Unhappy Parse the string, reading and wrting file

I have a .tar file (10MB) in hexidecimal code, I need manipulate and output the data in the tar file onto the web. First, I read the .tar file into program as one string and I want to parse up the string into pieces at every space (bar), and then write to another file line by line. I wrote ParseString subroutine, for some reason, it can only parse the string if the reading file is a text-only format, it doesn't parse string if the reading file is other formats, how can I break this file (string) into pieces? Help!


Option Explicit ' General declaration
Dim objFS As New FileSystemObject

Private Sub openAndReadWriteFile()

Const forreading = 1
Const TristateFalse = 0

Dim mFile As File 'Another file object
Dim objTS 'TextStream object for reading file
Dim strSearchThis As String
Dim RTxtStream As TextStream

'Open the reading tar file
Set mFile = objFS.GetFile("C:\1071-4\Tut08\JAN1504.tar")
Set objTS = mFile.OpenAsTextStream(forreading, TristateFalse)

strSearchThis = objTS.Read(mFile.Size) 'Read file

Call ParseString(strSearchThis)

Call objTS.Close
'Call mTxtStream.Close

End Sub

Private Sub Form_Load()
Call openAndReadWriteFile ' Open and read file
End Sub

Sub ParseString(StringToParse As String, Optional Delimiter As String = " ")
Dim mTxtStream As TextStream 'TextStream object for writing file
Dim mFile As File

'Create and open the writing file
Call objFS.CreateTextFile("c:\1071-4\Tut08\fastwrite8.txt")
Set mFile = objFS.GetFile("C:\1071-4\Tut08\fastwrite8.txt")
Set mTxtStream = mFile.OpenAsTextStream(ForWriting)

Dim lngStartPos As Long
Dim lngNextPos As Long
Dim strTemp As String

lngStartPos = 1

Do
lngNextPos = InStr(lngStartPos, StringToParse, Delimiter)

If lngNextPos = 0 Then
' For when we get to the end of the file
strTemp = Mid$(StringToParse, lngStartPos, Len(StringToParse) - lngNextPos + 1)
Else
strTemp = Mid$(StringToParse, lngStartPos, lngNextPos - lngStartPos + 1)
End If

Call mTxtStream.WriteLine(strTemp)

lngStartPos = lngNextPos + 1
DoEvents
Loop Until lngNextPos = 0

End Sub


The .tar file looks like this:

FF14073900000F01040451 FF1B0900000000000000009C9C FF100901030500010203008796 FF110901040700010102001626 FF120B84697EF064726BF080F0403C FF14073900000F01040451 FF1B0900000000000000009999 FF10090102020000000102878F FF11090101010000000102171D FF120B686489F0F0F06D5A80F0409C
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On