Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Find text before/between/after two target strings


Function SplitText( ByVal InString As String , Tag1 As String , Tag2 As String , Before As String , Between As String , After As String ) As Boolean
'returns true if the tag pair is found
Dim PosTag1 As Long , PosTag2 As Long
PosTag1 = InStr(InString, Tag1)
PosTag2 = InStr(PosTag1 + Len(PosTag1), InString, Tag2, vbTextCompare)
If PosTag1 > 0 Then
   Before = Left$(InString, PosTag1 - 1)   'string found
    If PosTag2 > 0 Then
       Between = Mid $(InString, PosTag1 + Len(Tag1), PosTag2 - PosTag1 - Len(Tag2))
       After = Mid $(InString, PosTag2 + Len(Tag2))
       SplitText = True
    End If
End If