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
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
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也可以 :)
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
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
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也可以 :)
http://expert.csdn.net/Expert/topic/3049/3049570.xml?temp=.4477045