functionj countchar(str as string,char as string) as long
dim i as long
dim j as long
for i=1 to len(str)
if mid(str,i,1)=char then
j=j+1
end if
next
countchar=j
end function
dim i as long
dim j as long
for i=1 to len(str)
if mid(str,i,1)=char then
j=j+1
end if
next
countchar=j
end function
VBA.MsgBox GetRepeatCount("aa aa aa jjsajdlka", "aa")
End Sub
Public Function GetRepeatCount(S As String, Find As String) As Long
GetRepeatCount = (VBA.Len(S) - VBA.Len(VBA.Replace(S, Find, ""))) \ VBA.Len(Find)
End Function
dim i as long
dim j as long
for i=1 to len(str)
if mid(str,i,1)=char then
j=j+1
end if
next
countchar=j
end function
这样的方法很好
如下:
q=0
m=len(字符串)
for i=1 to m
if mid(字符串,i,1)="A" and mid(字符串,i+1,1)="A" then
q=q+1 (q即为"AA"的个数)
end if
next i