Between_2Chars

Returns if a char was found between two defined characters.
Like find if Loss was found between ( and ) in a larger string.
Similar to Between_HTMLTag but this one is open to anything.

CodeFunctionName
What is this?

Public

Tested

Original Work
Function Between_2Chars(FindStr, inLargeStr, Optional Between_Char1 = "(", Optional and_Char2 = ")")
    ' Finds if a word is found anywhere between Char1 and Char2
    ' Returns 1 or 0
    Rett = 0
    StartPoint = VBInstr(FindStr, inLargeStr)
    If StartPoint > 0 Then Rett = Between_2Chars_ByIndex(StartPoint, inLargeStr, Between_Char1, and_Char2)
    Between_2Chars = Rett
End Function

Function Between_2Chars_ByIndex(LocIndex, inLargeStr, Optional Between_Char1 = "(", Optional and_Char2 = ")")
    ' Finds if a word is found anywhere between Char1 and Char2
    ' Returns 1 or 0
    Rett = 0
    Found1 = 0
    Found2 = 0
    For I = LocIndex To 1 Step -1
        If UCase(Mid(inLargeStr, I, Len(Between_Char1))) = UCase(Between_Char1) Then            ' Found open before we find close
            Found1 = I
            Exit For
        ElseIf UCase(Mid(inLargeStr, I, Len(and_Char2))) = UCase(and_Char2) Then    ' Found close before Open
            Found1 = -1
            Exit For
        End If
    Next
    ' Found1 either 0, -1 or I
    For I = LocIndex To Len(inLargeStr)
        If UCase(Mid(inLargeStr, I, Len(Between_Char1))) = UCase(Between_Char1) Then            ' Found open before we find close
            Found2 = -1
            Exit For
        ElseIf UCase(Mid(inLargeStr, I, Len(and_Char2))) = UCase(and_Char2) Then    ' Found close before Open
            Found2 = I
            Exit For
        End If
    Next
    If Found1 > 0 And Found2 > 0 Then Rett = 1 ' Found2 either 0, -1 or I
'        Rett = 1
'    ElseIf Found1 < 0 And Found2 < 0 Then
'        Rett = 0 ' 2
'    End If
   
ByeBye:
    Between_2Chars_ByIndex = Rett
End Function

FindStr, inLargeStr, Optional Between_Char1 = "(", Optional and_Char2 = ")"
Or
LocIndex, inLargeStr, Optional Between_Char1 = "(", Optional and_Char2 = ")"

Views 105

Downloads 41

CodeID
DB ID