查看: 10  |  回复: 0
  VB6 找到字符串1中出现字符串2的次数
楼主
发表于 昨天 18:47

新建From1(窗体),新建Command1(按钮CommandButton),代码:

Private Sub Command1_Click()
    Debug.Print f_CountTimes("a1b12c1d12e", "12")
End Sub

Private Function f_CountTimes(strW$, strFindWord$) As Long
    ' 统计abc出现次数
    Dim lngCount&, lngPos&
    
    lngPos = InStr(strW, strFindWord)
    Do While lngPos > 0
        lngCount = lngCount + 1
        lngPos = InStr(lngPos + 1, strW, strFindWord)
    Loop
    
    f_CountTimes = lngCount
End Function

运行结果:

2


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com