Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB
Expertise: Beginner
Feb 17, 2009

Use GetBetween to Parse a String Between Two Strings

This tips shows how to use GetBetween to parse and extract a string between two strings. GetBetween returns the extracted string, if found.

Public Function GetBetween(ByRef sSearch As String, ByRef sStart As String, ByRef sStop As String, _
                                                    Optional ByRef lSearch As Long = 1) As String
    lSearch = InStr(lSearch, sSearch, sStart)
    If lSearch > 0 Then
        lSearch = lSearch + Len(sStart)
        Dim lTemp As Long
        lTemp = InStr(lSearch, sSearch, sStop)
        If lTemp > lSearch Then
            GetBetween = Mid$(sSearch, lSearch, lTemp - lSearch)
        End If
    End If
End Function
Zachary Edwards
Thanks for your registration, follow us on our social networks to keep up-to-date