Public Class 例5_6

    Private Sub 例5_6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim A(26) As Integer
        Dim s As String, letter As String
        Dim l As Integer, i As Integer, index As Integer
        s = InputBox("请输入一个字符串")
        l = Len(s)                                  '获取字符串的长度
        For i = 1 To l
            letter = UCase(Mid(s, i, 1))    '取出一个字符，并将小写字母转换为大写字母
            If letter >= "A" And letter <= "Z" Then '挑选字母进行统计
                index = Asc(letter) - 64                '将字母A～Z转换为数字1～26
                A(index) = A(index) + 1                 '统计每个字母出现的次数
            End If
        Next i
        Console.Write("字母" & vbTab)
        Console.WriteLine("出现次数")
        For i = 1 To 26                               '输出统计结果
            Console.WriteLine(Chr(64 + i) & vbTab & A(i))
        Next i
    End Sub
End Class