VB Code:
Public Function IsGoodInStrCount(Optional fLigaturesToo As Boolean) As Boolean
' verify correct InStrCount returns, 20021005
' returns True if all tests are passed
' replace "InStrCount" with the name of your function to test
Dim fFailed As Boolean
Dim Text As String
If InStrCount("ababa", "a") <> 3 Then Stop: fFailed = True
If InStrCount("ababa", "ab") <> 2 Then Stop: fFailed = True
If InStrCount("ababa", "aba") <> 1 Then Stop: fFailed = True
If InStrCount("ababa", "abb") <> 0 Then Stop: fFailed = True
If InStrCount("ababa", "") <> 0 Then Stop: fFailed = True
If InStrCount("", "a") <> 0 Then Stop: fFailed = True
If InStrCount("aaaa", "aa") <> 2 Then Stop: fFailed = True
If InStrCount("aAaA", "a") <> 2 Then Stop: fFailed = True
If InStrCount("aAaA", "a", , vbTextCompare) <> 4 Then Stop: fFailed = True
If InStrCount("aAaA", "A", , vbTextCompare) <> 4 Then Stop: fFailed = True
' unicode
If InStrCount("€€€", "€") <> 3 Then Stop: fFailed = True
If InStrCount("[a]{a}", "{A}", , vbTextCompare) <> 1 Then Stop: fFailed = True
' Common chars when parsing Unix "man" pages...
Text = Replicate05(10, "{|}[/][\]{{||}}[/][\]{{{|||}}}[/][\]")
If InStrCount(Text, "{|}", , vbTextCompare) <> 10 Then Stop: fFailed = True
' the 4 stooges: š/Š, œ/Œ, ž/Ž, ÿ/Ÿ (154/138, 156/140, 158/142, 255/159)
If InStrCount("Hašiš", "Š", , vbTextCompare) <> 2 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 InStrCount("Straße", "ss", , vbTextCompare) <> 1 Then Stop: fFailed = True
End If
' well done
IsGoodInStrCount = Not fFailed
End Function
Public Function Replicate05(ByVal Number&, Pattern$) As String
' based on Replicate03 by Larry Serflaten, [email]
[email protected][/email], 20001206
Dim LP As Long
If Number > 0 Then
LP = Len(Pattern)
Select Case LP
Case Is > 1
Replicate05 = Space$(Number * LP)
Mid$(Replicate05, 1, LP) = Pattern
If Number > 1 Then
Mid$(Replicate05, LP + 1) = Replicate05
End If
Case 1
Replicate05 = String$(Number, Pattern)
End Select
End If
End Function