Solved

PARSE FROM STRING

Posted on 2001-08-11
6
148 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

929 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

13 Experts available now in Live!

Get 1:1 Help Now