str="aaa1ffff1hh1"求str中"1"的个数, 返回3个这个函数如何写????
 

解决方案 »

  1.   

    Private Sub Form_Load()
        MsgBox strTime("aaa1ffff1hh1", "1")
    End SubPrivate Function strTime(ByVal Str As String, ByVal str2 As String) As Integer
        Dim I As Integer
        Dim J As Integer
        J = 0
        For I = 1 To Len(Str)
            If Mid(Str, I, 1) = str2 Then
                J = J + 1
            End If
        Next
        strTime = J
    End Function
      

  2.   

    Dim Tmp() As String
        Dim str As String    str = "aaa1ffff1hh1"
        Tmp = Split(str, "1")
        MsgBox UBound(Tmp)
      

  3.   

    Private Sub Form_Load()    MsgBox getNumber("aaa1ffff1hh1", "1")End SubFunction getNumber(strSource As String, strSplit As String) As Integer
        Dim Tmp() As String
        Tmp = Split(strSource, strSplit)
        getNumber = UBound(Tmp)
    End Function
      

  4.   

    其实只要一句话就可以做到:
    str = "aaa1ffff1hh1"
        
    MsgBox Len(Replace(str, "1", "11")) - Len(str)
      

  5.   

    Private Sub Command1_Click()
    MsgBox UBound(Split("aaa1ffff1hh1", "1"))
    MsgBox strnumber("aaa1ffff1hh1", "1")
    End Sub
    Function strnumber(ByVal x As String, ByVal findstr As String) As Long
    Dim temp As Long
    x = Replace(x, " ", "")
    temp = Len(x)
    x = Replace(x, findstr, "")
    strnumber = (temp - Len(x)) \ Len(findstr)
    End Function
      

  6.   

    Len(str)-Len(Replace(str, "1", "")) ,呵呵
      

  7.   

    Len(str)-Len(Replace(str, "1", "")) 这种最好了
      

  8.   

    Len(str)-Len(Replace(str, "1", "")) 这种最好了
    =====================
    但这种不通用。
      

  9.   

    lihonggen0(李洪根,MS MVP,标准答案来了)
    高人啊,你的两种方法体现了中国人的智慧,你真是论坛的希望,相比之下,偶真是什么都不是啊~~
      

  10.   

    dim i as integer 
    dim j as integer 
    j=0
    For i = 1 To Len(Str)
    If InStr(CStr(i), "1") <> 0 Then
      j=j+1
    end if
    next
      

  11.   

    lihonggen0(李洪根,MS MVP,标准答案来了) 与 northwolves(野性的呼唤)的方法一个样,但评价前者的就说他是论坛的希望,评价后者就说他的方法不通用,呵呵,星星少了待遇都不一样了