Počet zobrazení stránky

2011-04-22

GetBetween function

Public Function getbetween(ByVal input As String, ByVal str1 As String, _
             ByVal str2 As String, ByVal index As Integer) As String
    
        If str1 <> str2 Then
            Dim tempdata As String = input.Replace(str1, "Ş")
            Dim data As String = tempdata.Replace(str2, "®")
            Dim tempvalue() As String = data.Split("Ş")
            Return tempvalue(index + 1).Split("®")(0)
        ElseIf str1 = str2 Then
            Dim data As String = input.Replace(str1, "?")
            Return Data.Split(str1)(index + 1)
        End If
    End Function

Usage:
getbetween("the text we want to get the value from","the first string the text is located between", "the second string the text is located between", "which value to return if there are more matches")

Example:
getbetween("Some testing string <|?TROLOL?|> blah blah  <|?some shit?|> blah blah blAH", "<|?", "?|>", 0)
'returns "TROLOL"

getbetween("Some testing string <|?TROLOL?|> blah blah  <|?some shit?|> blah blah blAH", "<|?", "?|>", 1)
'returns "some shit"

Žádné komentáře:

Okomentovat