Parsing/Extracting string


I have this string:

Dim strFileLine As String

strFileLine = "0&²uŽfϦ٠ª bÎlÎ         @¤ÐÒãÒ—ð  É^¨P        O L Y M P U S    âdss     4692                þÿÿÿÿÿ040629115015040629115019000004ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ, ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿj  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ                                                                                                    ÿ "

Yeah I know it's dirty. I need to extract the numbers 4692 from    "O L Y M P U S    âdss     4692"
And also:


Any ideas?

Who is Participating?
PePiConnect With a Mentor Commented:

the position for the "4692" thingy is 91 7 for the long numeric string is 117. so to extract the first go:

     strFirstField = Mid(strFileLine, 91, 4)

and for the second field:

    strSecondField = Mid(strFileLine, 117, 30)

i hope this is what you are looking for. cheers!
David LeeCommented:
If the strings you want are always in the same position, then open the file in binary mode, read in the areas you want as byte fields, then use the CHR() function to convert them back to characters.
TrancedifiedAuthor Commented:
The file opens in binary but not all the way, it only gives me: 0&²uŽfϦ٠ª bÎl (the first few characters)

I had to do it another way. But  yeah the things i want to extract are all in the same position.
Do you have an example after the file is read?

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


for 4692

    debug.print Mid(strFileLine, InStr(strFileLine, "4692", 4)


   debug.print Mid(strFileLine, InStr(strFileLine, "040629115015040629115019000004", 30)
TrancedifiedAuthor Commented:

4692 might be a different ID number, can that "pickup" 4 numbers?


040629115015040629115019000004 same thing (Can it "pickup" just those numbers? and not necessarily "040629115015040629115019000004")???

sorry, i did not understand the problem properly.

are these values in the same position all the time? and is the length fixed?

TrancedifiedAuthor Commented:
yes for both :) IT's ok my fault for not explaining too well
David LeeConnect With a Mentor Commented:
This is what I had in mind.  I don't feel comfortable processing binary input in a string variable.  I used the offsets listed here in this code.  The actual offsets from the file you're reading the data in from might actually be different.

Private Sub Command1_Click()
    Dim strOne As String, _
        strTwo As String, _
        intPosition As Integer, _
        bytChar As Byte
    Open "C:\" For Binary As #1
    For intPosition = 1 To 146
        Get #1, intPosition, bytChar
            Select Case intPosition
                Case 91 To 94
                    strOne = strOne & Chr(bytChar)
                Case 117 To 146
                    strTwo = strTwo & Chr(bytChar)
            End Select
    Close #1
End Sub
TrancedifiedAuthor Commented:
Thanks for the advice :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.