[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Parsing/Extracting string

Posted on 2004-09-02
9
Medium Priority
?
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 11968579
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
ID: 11968589
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
ID: 11968637

for 4692

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

for

   debug.print Mid(strFileLine, InStr(strFileLine, "040629115015040629115019000004", 30)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:Trancedified
ID: 11968655
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
 
LVL 6

Expert Comment

by:PePi
ID: 11968690
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
ID: 11968695
yes for both :) IT's ok my fault for not explaining too well
0
 
LVL 6

Accepted Solution

by:
PePi earned 1200 total points
ID: 11968922

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 800 total points
ID: 11969155
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
ID: 11969335
Thanks for the advice :)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

650 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