VB-获取某字符在其中出现的次数

 1 '方法1:
 2         Dim str As String
 3         str = "12345678"
 4         MsgBox(UBound(Split(str, "3")))  
 5  
 6 '方法2:
 7         Dim n&, j&
 8         j = 0
 9         n = InStr(1, text1.Text, "/ITEMNAME")
10         While n <> 0
11             n = InStr(n + 1, text1.text, text2.text)
12             j = j + 1
13         Wend 
14         Print(j)
15 
16  
17 '方法3:
18 '调用 strCount(TextBox8.Text, "/ITEMNAME")
19  
20     Function strCount(ByVal strA As String, ByVal strB As String) As Long
21         Dim lngA As Long
22         Dim lngB As Long
23         Dim lngC As Long
24         lngA = Len(strA)
25         lngB = Len(strB)
26         lngC = Len(Replace(strA, strB, ""))
27         strcount = (lngA - lngC) / lngB
28         MsgBox(strCount)
29  
30  
31     End Function

 

posted @ 2014-07-28 23:05  不平凡总在于坚持!  阅读(1273)  评论(0编辑  收藏  举报