vb怎么统计一个单词中每个字母出现的频率?
1个回答
展开全部
Dim dststr As String = InputBox("请输入要统计的单词")
Dim b(26) As Integer
Dim a As Integer
Dim str As String = ""
For i = 1 To 26
b(i) = 0
Next
For i = 1 To Len(dststr)
a = Asc(Mid(dststr, i, 1))
If a >= 97 And a <= 122 Then
b(a - 96) += 1
End If
If a >= 65 And a <= 90 Then
b(a - 64) += 1
End If
Next
For i = 1 To 26
If b(i) <> 0 Then
str = str & "字母" & Chr(i + 64) & "和" & Chr(i + 96) & "出现的次数是" & b(i) & "次" & vbCrLf
End If
Next
TextBox6.Text = str
追问
能给出举例就好了,不过还是谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询