Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PARSE FROM STRING

Posted on 2001-08-11
6
Medium Priority
?
160 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 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
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!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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

670 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