|
这是我碰到的一个问题,后来找老师写的一个函数,感觉这个函数在很多方面都能用上,所以和大家一起分享。
Public Function GetDisplayMax(tcWords As String, tcWord As String) As Integer
Dim i As Integer, m As Integer
Dim s As String
Dim c As String
Dim n As Integer
Dim l As String
Dim intMaxCount As Integer
s = tcWords
m = Len(s)
For i = 1 To m
s = Mid(tcWords, i, m - i + 1)
c = Left(s, Len(tcWord))
'Debug.Print i, s, c
If l <> c Then
n = 0
End If
If c = tcWord Then
i = i + Len(tcWord) - 1
n = n + 1
'Debug.Print i, n & "个"
End If
If n > intMaxCount Then intMaxCount = n
l = c
Next i
GetDisplayMax = intMaxCount
End Function
|
|