会员登录 - 用户注册 - 网站地图 Office中国(office-cn.net),专业Office论坛
当前位置:主页 > 技巧 > Access技巧 > 模块函数VBA > 正文

怎样取得一个字符串在另外一个字符串中出现的次数?

时间:2004-02-21 00:00 来源:access911.net 作者:cg1 阅读:

 

 

 

 

 

 

问题:
 

  怎样取得一个字符串在另外一个字符串中出现的次数? 

 


方法一:

 
Function strCount(strA As String, strB As String) As Long
    Dim lngA As Long
    Dim lngB As Long
    Dim lngC As Long
    lngA = Len(strA)
    lngB = Len(strB)
    lngC = Len(Replace(strA, strB, ""))
    strCount = (lngA - lngC) / lngB
End Function

 


方法二:

 
Public Function sCount(String1 As String, String2 As String) As Integer 
    Dim I As Integer, iCount As Integer 
    I = 1 
    Do 
           If (I > Len(String1)) Then Exit Do 
           I = InStr(I, String1, String2, vbTextCompare) 
           If I Then 
              iCount = iCount + 1 
              I = I + 2 
              DoEvents 
           End If 
    Loop While I 
    sCount = iCount 
End Function 

 

 

 

 

 

 

(责任编辑:admin)

顶一下
(1)
100%
踩一下
(0)
0%
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价: