dim s() as integer s=split(str,",")for i=0 to ubound(s) if s(i)="04" then iCount=iCount+1 next i大致就这样了,你自己再看看
dim b() as string b=split("01,04,01,12,13,14,04,35,67,89,01,55",",") dim i as integer dim n as integer for i=0 to uBound(b) if b(i)="04" then n=n+1 next debug.print n
Option ExplicitFunction SubStrCount(ByVal sData As String, ByVal sSub As String) As Long SubStrCount = (Len(sData) - Len(Replace(sData, sSub, ""))) \ Len(sSub) End FunctionPrivate Sub Form_Load() Debug.Print SubStrCount("01,04,01,12,13,14,04,35,67,89,01,55", "04") Debug.Print SubStrCount("01,04,01,12,13,14,04,35,67,89,01,55", "01") End End Sub
s=split(str,",")for i=0 to ubound(s)
if s(i)="04" then iCount=iCount+1
next i大致就这样了,你自己再看看
b=split("01,04,01,12,13,14,04,35,67,89,01,55",",")
dim i as integer
dim n as integer
for i=0 to uBound(b)
if b(i)="04" then n=n+1
next
debug.print n
msgbox uBound(b)
简单明了
msgbox uBound(b)
简单明了==========================================================这个方法好,不过应该在改下,把"04"改成",04,"更好些。
SubStrCount = (Len(sData) - Len(Replace(sData, sSub, ""))) \ Len(sSub)
End FunctionPrivate Sub Form_Load()
Debug.Print SubStrCount("01,04,01,12,13,14,04,35,67,89,01,55", "04")
Debug.Print SubStrCount("01,04,01,12,13,14,04,35,67,89,01,55", "01")
End
End Sub