VBA 收集 - 统计字符串出现次数


Function 统计字符串出现次数(sourceStr As String, searchStr As String) As Long
On Error GoTo Error_Handler

    统计字符串出现次数 = UBound(Split(sourceStr, searchStr))
    
Error_Handler_Exit:
    On Error Resume Next
    Exit Function
    
Error_Handler:
    Resume Error_Handler_Exit
    
End Function

测试


Sub test()
    msg = "出现 " & 统计字符串出现次数("大家好,我是笨笨,笨笨的笨,笨笨的笨,谢谢!", "笨") & " 次"
    MsgBox msg, vbOKOnly + vbInformation, "统计出现次数"
End Sub
VBA 收集 - 统计字符串出现次数

Function 统计字符串出现次数(sourceStr As String, searchStr As String) As Long

On Error GoTo Error_Handler

统计字符串出现次数 = UBound(Split(sourceStr, searchStr))

Error_Handler_Exit:

On Error Resume Next

Exit Function

Error_Handler:

Resume Error_Handler_Exit

End Function

https://www.xianxiaba.com/kejitongxun/25825516.html

本站所有信息均由爬虫抓取,用于机器学习,如有发现包括但不限于“违法、违规信息、侵权信息”,请联系站长删除处理。