Solved

PARSE FROM STRING

Posted on 2001-08-11
6
146 Views
Last Modified: 2010-05-02
ok-

have a string:

05936-7015632987-1259

i want to only extract between

-701 and -1259

the length of the string in between those two varies.

how do i do it.

thanks in advance.
0
Comment
Question by:jsopher
6 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 6376228
Dim x As String
Dim sParse As String


x = "05936-7015632987-1259"

sParse = Mid(x, InStr(x, "-701") + 4)
sParse = Left(sParse, InStr(sParse, "-1259") - 1)

MsgBox sParse


OR maybe

Dim x As String
Dim sParse As String


x = "05936-7015632987-1259"

sParse = Mid(x, 10, 7)
0
 
LVL 5

Accepted Solution

by:
jklmn earned 100 total points
ID: 6376231
Private Sub Command1_Click()
Dim s As String, s1 As String, s2 As String, n1 As Long, n2 As Long
s = "05936-7015632987-1259"
s1 = "-701"
s2 = "-1259"
n1 = InStr(s, s1) + Len(s1)
n2 = InStr(s, s2) - n1
s = Mid(s, n1, n2)
Print s
0
 

Author Comment

by:jsopher
ID: 6376240
thanks man, nice code
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 38

Expert Comment

by:PaulHews
ID: 6376250
If you can count on the hyphen being there, but not 701 or 1259, (although assuming a sub-string with the same length being in their places) then you would need the following.

Option Explicit

Private Sub Command1_Click()
    Debug.Print fParse("05936-7015632987-1259")
End Sub

Public Function fParse(strFull As String) As String
    Dim lngS As Long, lngL As Long
   
    lngS = InStr(strFull, "-") + 4
    lngL = InStrRev(strFull, "-") - lngS
    If lngL > 0 Then
        fParse = Mid$(strFull, lngS, lngL)
    End If
   
End Function


0
 
LVL 18

Expert Comment

by:deighton
ID: 6376261
I see, you're giving your friend the points

my code was first, and is actually more economical & gave the same results, didn't it


EXPLAIN YOURSELF!!!
0
 

Author Comment

by:jsopher
ID: 6376325
first off, i don't have friends on EE - i have resources for my vb q's.

i used the code i felt to work the best.

if you have a problem with that, take it up with the folks that run this terrific site.

NO MORE EXPLANATION NEEDED! @#$%@%$@$#^%@#$
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

705 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

16 Experts available now in Live!

Get 1:1 Help Now