Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PARSE FROM STRING

Posted on 2001-08-11
6
Medium Priority
?
161 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 400 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

876 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