Solved

PARSE FROM STRING

Posted on 2001-08-11
6
157 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
[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
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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
Course of the Month7 days, 22 hours left to enroll

617 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