jsopher
asked on
PARSE FROM STRING
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks man, nice code
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-1 259")
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
Option Explicit
Private Sub Command1_Click()
Debug.Print fParse("05936-7015632987-1
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
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!!!
my code was first, and is actually more economical & gave the same results, didn't it
EXPLAIN YOURSELF!!!
ASKER
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! @#$%@%$@$#^%@#$
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! @#$%@%$@$#^%@#$
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)