输入一行字符,分别统计其中各英文字母出现的个数。(不区分大小写)

2025-01-06 19:45:50
推荐回答(2个)
回答1:

以下是在VB中的写法,修改于其他网友的版本,不区分大小写:
Dim tmp$, i&, lenstr&, sum%
tmp = LCase(Text1.Text)
lenstr = Len(tmp)
For i = 97 To 122
sum = lenstr - Len(Replace(tmp, Chr(i), ""))
If sum > 0 Then Print Chr(i) & "次数为:" & sum
Next

回答2:

Private Sub Command1_Click()
Dim i As Integer, strTxt As String, abc(25) As Integer, bytAsc As Byte, strTemp As String
strTxt = UCase(Text1.Text)
For i = 1 To Len(strTxt)
bytAsc = Asc(Mid(strTxt, i, 1)) - 65
If bytAsc >= 0 And bytAsc <= 25 Then abc(bytAsc) = abc(bytAsc) + 1
Next
For i = 0 To 25
If abc(i) > 0 Then strTemp = strTemp & Chr(i + 65) & " 出现 " & abc(i) & " 次" & vbCrLf
Next
Text2.Text = strTemp
End Sub