Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Get between two strings function modification

$
0
0
I have a function that I am using to get a string from between two substrings. The modification is that I need the function to have multiple stopping parameters. So if it finds any of the sStop strings it will work. Can anyone help me modify this function?

Code:

    Private Function GetBetween(ByVal sSearch As String, ByVal sStart As String, ByVal sStop As String, Optional ByVal lSearch As Integer = 1) As String
        Dim lTemp As Long

        lSearch = InStr(lSearch, sSearch, sStart)
        If lSearch > 0 Then
            lSearch = lSearch + Len(sStart)
            lTemp = InStr(lSearch, sSearch, sStop)
            If lTemp > lSearch Then Return Trim(Mid$(sSearch, lSearch, lTemp - lSearch))
        End If
        Return vbNullString
    End Function

EDIT:
I'd also like to make it inclusive so that the start and end of the string are included in the output string.

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>