Function SubStringCount(ByVal sSource As String, ByVal sFind As String) As Integer
SubStringCount = 0
Dim iLenFind As Integer, iStart As Integer
iLenFind = Len(sFind)
iStart = 1
Dim iPtr As Integer
iPtr = 0
Dim iPos As Integer
iPos = InStr(iStart, sSource, sFind, CompareMethod.Text)
If iPos > 1 Then
SubStringCount = 1
While (iPos)
iPos = InStr(iPos + iLenFind, sSource, sFind, CompareMethod.Text)
If iPos > 0 Then
SubStringCount = SubStringCount + 1
End If
End While
End If
End Function
本文介绍了一个用于计算一个字符串在另一字符串中出现次数的VBScript函数。该函数通过循环使用InStr方法来查找子字符串的位置,并根据位置判断是否继续搜索,以此来计算总的出现次数。
530

被折叠的 条评论
为什么被折叠?



