如题,谢谢!!!

解决方案 »

  1.   

    统计一个字或词出现的次数的函数Public Function CountSubstrings(target As String, _
        template As String, CaseSensitive As Boolean) _
        As Integer'   Returns the number of times template occurs in target.
    '   Returns -1 if either string is blank or if templateis longer than target. If CaseSensitive is true, performs a case-sensitive comparison for text. If false, the comparison is case-insensitive.
    Dim pos1 As Integer, pos2 As Integer, count As IntegerIf Len(target) = 0 Or Len(template) = 0 Or _
      Len(template) > Len(target) Then
        CountSubstrings = -1
        Exit Function
     End If count = 0
     pos2 = 1
        
    Do
      If CaseSensitive Then
        pos1 = InStr(pos2, target, template, vbBinaryCompare)
      Else
        pos1 = InStr(pos2, target, template, vbTextCompare)
      End If
      If pos1 > 0 Then
        count = count + 1
        pos2 = pos1 + 1
      End If
    Loop Until pos1 = 0CountSubstrings = countEnd Function 这个函数名叫做CountSubstrings。你在搜索指定字符串,寻找需要模版字符串,在不区分大小写并指定了布林逻辑运算元的情况下搜索文本的时候可以使用它。注意,这个代码在下面三种情况下可能会出现错误:1 目标字符串是空白的;2 模版字符串是空白的;3 模版字符串长于目标字符串。发生三种情况中任一种,函数的返回值是-1。
      

  2.   

    程序有一处Bugpos2 = pos1 + 1    应该改为:   pos2 = pos1 + Len(template)
      

  3.   

    统计汉字英文、单词、数字、标点个数:
    http://vbboshi.myrice.com/vbtech/value/page_2/file32.htm