Grabbing a String between two delimiters

  • Thread starter Thread starter Kirk
  • Start date Start date
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
 
Kirk,

Use the Split function. E.g.,

Dim S As String
Dim Arr As Variant
S = "xyz\abc\defgh"
Arr = Split(S, "\")
MsgBox Arr(1)


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
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
 
Back
Top