Solved

Parsing/Extracting string

Posted on 2004-09-02
9
194 Views
Last Modified: 2010-05-02
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
Comment
Question by:Trancedified
  • 4
  • 3
  • 2
9 Comments
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
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
 
LVL 1

Author Comment

by:Trancedified
Comment Utility
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
 
LVL 6

Expert Comment

by:PePi
Comment Utility

for 4692

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

for

   debug.print Mid(strFileLine, InStr(strFileLine, "040629115015040629115019000004", 30)
0
 
LVL 1

Author Comment

by:Trancedified
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 6

Expert Comment

by:PePi
Comment Utility
sorry, i did not understand the problem properly.

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

0
 
LVL 1

Author Comment

by:Trancedified
Comment Utility
yes for both :) IT's ok my fault for not explaining too well
0
 
LVL 6

Accepted Solution

by:
PePi earned 300 total points
Comment Utility

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
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 200 total points
Comment Utility
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
 
LVL 1

Author Comment

by:Trancedified
Comment Utility
Thanks for the advice :)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now