急!!VB字符统计:在文本框中输入一串字符,在下面的列表框中显示出每个26个英文字母出现的次数。

2024-12-02 14:42:32
推荐回答(1个)
回答(1):

Private Sub Command1_Click()
''''统计文本框中26个英文字符出现的个数
Dim Str As String
Dim Count(25) As Integer, Strlen As Integer, index As Integer
Dim ch As String
Str = Text1
Strlen = Len(Str)

''''利用循环将str中每个字符取出来
For i = 1 To Strlen
ch = UCase(Mid(Str, i, 1))
index = Asc(ch) - 65
If index >= 0 And index <= 25 Then
Count(index) = Count(index) + 1
End If
Next

For i = 0 To 25
List1.AddItem Chr(65 + i) & " " & Count(i)
Next
End Sub