• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Parsing/Extracting string

Hello,

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:

040629115015040629115019000004

Any ideas?

Chris
0
Trancedified
Asked:
Trancedified
  • 4
  • 3
  • 2
2 Solutions
 
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.
0
 
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?

Chris
0
 
PePiCommented:

for 4692

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

for

   debug.print Mid(strFileLine, InStr(strFileLine, "040629115015040629115019000004", 30)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TrancedifiedAuthor Commented:
PePi,

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

for

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

chris
0
 
PePiCommented:
sorry, i did not understand the problem properly.

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

0
 
TrancedifiedAuthor Commented:
yes for both :) IT's ok my fault for not explaining too well
0
 
PePiCommented:

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!
0
 
David LeeCommented:
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:\MyFile.xxx" 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
    Next
    Close #1
End Sub
0
 
TrancedifiedAuthor Commented:
Thanks for the advice :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now