Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
Dim s As String
Dim s1 As String
s = "12345543211235555678234aaawwwqqwwww1222222333324wsewwerewrew"
s1 = "w"
'求s中s1的个数
Dim i As Long, temps As String, j As Long
Dim t As Long
Dim a As Long, b As Long
Dim sum As Long
'(1)
t = GetTickCount
For a = 0 To 10000
temps = Replace(s, s1, "")
i = Len(s) - Len(temps)
i = i / Len(s1)
Next
MsgBox GetTickCount - t, , i
'(2)
t = GetTickCount
For a = 0 To 10000
j = UBound(Split(s, s1))
Next
MsgBox GetTickCount - t, , j
'(3)
t = GetTickCount
For a = 0 To 10000
b = 1
j = 0
Do
i = InStr(b, s, s1)
If i = 0 Then Exit Do
j = j + 1
b = i + 1
Loop
Next
MsgBox GetTickCount - t, , j
Private Sub Command1_Click()
Dim s, tempS As String
Dim s1 As String
Dim i, sum As Integer
s = "12345543211235555678234aaawwwqqwwww1222222333324wsewwerewrew"
s1 = "w"
sum = 0
'求s中s1的个数
For i = 1 To Len(s)
tempS = Mid(s, i, 1)
If tempS = s1 Then
sum = sum + 1
End If
Next
'SUM为W的个数
Private Sub Command1_Click()
Dim s As String
Dim s1 As String
s = "12345543211235555678234aaawwwqqwwww1222222333324wsewwerewrew"
s1 = "w"
'求s中s1的个数
Dim i As Long, temps As String
temps = Replace(s, s1, "")
i = Len(s) - Len(temps)
i = i / Len(s1)
'i即为所求
End Sub