如何统计输入的字符串中各字符出现的次数?

解决方案 »

  1.   

    flyingZFX(我飞!我飞!我飞呀飞!) :多少为宜?
      

  2.   

    Option ExplicitPrivate Sub Command1_Click()
    Dim s As String
    Dim l As Long
    Dim c As Strings = "fghdfghdfghdfghdfghdfgh"
    Do While LenB(s) > 0
        l = Len(s)
        c = Left(s, 1)
        s = Replace(s, c, "")
        Debug.Print c & ":" & l - Len(s) & "个"
    Loop
    End Sub
      

  3.   

    Private Sub Command1_Click()
    On Error Resume Next
    Dim i As Long, temp As String, all As New Collection
    For i = 1 To Len(Text1.Text)
    temp = Mid(Text1.Text, i, 1)
    all.Add temp & "出现了: " & UBound(Split(Text1.Text, temp)) & " 次!", temp
    Next
    For i = 1 To all.Count
    Debug.Print all(i)
    Next
    End SubPrivate Sub Form_Load()
    Text1.Text = "fantasyfan (fantasyfan)"
    End Sub
      

  4.   

    回复人: flyingZFX(我飞!我飞!我飞呀飞!) 逗~  ^o^o^o^o^o^o^o^o^o^o^o^
      

  5.   

    flyingscv(zlj)的方法比较巧妙,此方法比较好 :)再想一个比较不正常的方法:
    Dim Str As String, i As Integer
    Dim Temp() As String
    Str = "abcdefghijkolmnkqposcihugbuyvgfuxwncsaoungyzouyfxtncdjixzidnmizaxdsjgcnxhkbcaf"
    For i = 65 To 90
        Temp = Split(UCase(Str), Chr(i))
        MsgBox "字母 " & Chr(i) & " 共有 " & Format(UBound(Temp)) & " 个"
    Next i也可以 :)
      

  6.   

    flyingscv(zlj)的算法没什么问题,而且巧妙。northwolves(野性的呼唤)的在有大小写字母时会出问题。
      

  7.   

    晕,原来northwolves(野性的呼唤)早把我的方法说掉了 :)大小写不是问题,都用LCase或者UCase处理一下就可以了,就像我代码中那样
      

  8.   

    马甲:http://www.cctv.com/special/956/2/86993.html
      

  9.   

    最好是可以 用 VB直接打开的,不然就失去意义了,你说呢, koof78() ( ) 
    http://expert.csdn.net/Expert/topic/3049/3049570.xml?temp=.4477045
      

  10.   

    flyingscv(zlj) 太妙了,我的思路又开阔了很多~~
      

  11.   

    flyingscv(zlj)的算法就是妙,看了之后还想看:)
      

  12.   

    flyingscv(zlj)的方法真好,我又学了一招