Grabbing a String between two delimiters

K

Kirk

For some reason I can't seem to figure this one out. I
need to be able to determine a string that lies between
two delimeters.

Example:

xyz\abc\defgh

I need to be able to grab out the "abc" portion without
knowing the exact size of what the string will be between
the two delimters (\). In looking at a book I have there
was mention of a function called dhExtractString but it
appears not to work on Excell 2002 (SP2) unless there is
a reference that I need to add.

Any help would be appreciated. Thanks.

Kirk
 
K

Kent Prokopy

Try using the following function...

Debug.Print strReturnValue("xyz/abc/defgh","/","/")

Public Function strReturnValue(strMessageBody As String, strTag1 As String,
strTag2 As String) As String
Dim StartPos As Long
Dim EndPos As Long
StartPos = InStr(1, strMessageBody, strTag1, vbTextCompare) + Len(strTag1)
EndPos = InStr(StartPos, strMessageBody, strTag2, vbTextCompare)
If EndPos = 0 Then EndPos = StartPos
strReturnValue = Mid(strMessageBody, StartPos, EndPos - StartPos)
End Function
 
Top