Solved

Parsing/Extracting string

Posted on 2004-09-02
9
207 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 300 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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

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 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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 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