Public Function IsGoodInStr(Optional fLigaturesToo As Boolean) As Boolean
' verify correct InStr returns, 20021005
' returns True if all tests are passed
Dim fFailed As Boolean
' replace ".InStr01" with the name of your function
With New CInStrMarzo
If .InStr01("abc", "b") <> 2 Then Stop: fFailed = True
If .InStr01("abab", "ab") <> 1 Then Stop: fFailed = True
If .InStr01("abab", "aB") <> 0 Then Stop: fFailed = True
If .InStr01("abab", "aB", , vbTextCompare) <> 1 Then Stop: fFailed = True
If .InStr01("abab", "ab", 2) <> 3 Then Stop: fFailed = True
If .InStr01("abab", "ab", 3) <> 3 Then Stop: fFailed = True
If .InStr01("abab", "ab", 4) <> 0 Then Stop: fFailed = True
If .InStr01("aaabcab", "abc", 4) <> 0 Then Stop: fFailed = True
If .InStr01("abab", "", 4) <> 4 Then Stop: fFailed = True
If .InStr01("abab", "", 5) <> 5 Then Stop: fFailed = True
If .InStr01("", "", 4) <> 0 Then Stop: fFailed = True
If .InStr01("abab", "c") <> 0 Then Stop: fFailed = True
If .InStr01("abcdabcd", "abcd") <> 1 Then Stop: fFailed = True
If .InStr01("abab", "Ab") <> 0 Then Stop: fFailed = True
If .InStr01("abab", "Ab", , vbTextCompare) <> 1 Then Stop: fFailed = True
If .InStr01("a" & String$(50000, "b"), "a") <> 1 Then Stop: fFailed = True
' unicode
If .InStr01("a€€c", "€") <> 2 Then Stop: fFailed = True
' the 4 stooges: š/Š, œ/Œ, ž/Ž, ÿ/Ÿ (154/138, 156/140, 158/142, 255/159)
If .InStr01("Hašiš", "Š", , vbTextCompare) <> 3 Then Stop: fFailed = True
' ligatures textcompare (VBspeed entries do NOT have to pass this test)
If fLigaturesToo Then
' ligatures, a digraphemic fun house: ss/ß, ae/æ, oe/œ, th/þ
If .InStr01("Straße", "ss", , vbTextCompare) <> 5 Then Stop: fFailed = True
End If
End With
' well done
IsGoodInStr = Not fFailed
End Function
Back to InStr