'''
'''  FF_TALLYANY
'''  计数指定的字符字符串在字符串中的出现次数。
'''
'''  MainString 是字符串表达式，用来计算字符数。 
'''  MatchPattern 是单个的字符将被单独地搜寻列表︰ 
'''  任何一种匹配将导致计数递增为每个出现的该字符。
'''  请注意，重复的字符在 MatchPattern 不会增加计数。
'''  这个函数是区分大小写。 
'''
'  Function FF_TallyAny( ByRef sMainString   as String, _
'                        ByRef sMatchPattern as String _
'                        ) as Integer
''
''  FF_TALLYANY
''  Count the number of occurrences of specified characters strings within a string.
''
''  MainString is the string expression in which to count characters.  
''  MatchPattern is a list of single characters to be searched for individually: a match on 
''  any one of which will cause the count to be incremented for each occurrence of that 
''  character. Note that repeated characters in MatchPattern will not increase the tally.
''  This function is case-sensitive. 
''
Function FF_TallyAny( ByRef sMainString   as String, _
                      ByRef sMatchPattern as String _
                      ) as Integer

    Dim count as Integer
    Dim i     as Integer
    Dim y     as Integer 
    Dim z     as Integer
    Dim fDuplicate as Integer
    Dim nLenMatch as Integer = Len(sMatchPattern)
    
    
    If Len(sMainString) = 0 Then Return 0

    count = 0
    
    For y = 0 To nLenMatch - 1
       ' Make sure that we have not already searched for this character. It is
       ' possible that the MatchPattern could contain multiple copies of the character.
       ' For example:  MatchPattern = "bab"  ' we would only search for 'b' once, not twice.
       fDuplicate = False
       If y > 0 Then
          For z = 0 To y - 1
             If sMatchPattern[z] = sMatchPattern[y] Then
                fDuplicate = True
                Exit For
             End If   
          Next
       End If
 
       If fDuplicate = False Then
          ' Now do the count
          i = 1
          Do
             i = InStr(i, sMainString, Chr(sMatchPattern[y]))
             If i > 0 Then count += 1: i += 1
          Loop Until i = 0
       End If
    Next
    
    Return count

End Function
