编写一个程序,计算文件中每个字母出现的次数、每个单词出现的次数,并最终在屏幕上显示统计结果。

2024-11-30 10:57:45
推荐回答(1个)
回答1:

这里有个数字统计示例,如果要统计其他,就取得它的ASCII值,如果统计单词,根据英文单词的样子,一般是空格或标点进行分隔,可以对它们进行正则分开成数组,然后进行遍历。 作者:FlyMe联系方式:7826-452-10 Private Sub Command1_Click()
Dim a(1 To 30)
Dim c(0 To 9)
Dim i As Integer

Picture1.Cls
For i = 1 To 30
a(i) = Mid(Text1.Text, i, 1)
Next i
For i = 0 To 9
c(i) = 0
Next i
CountN a, c
For i = 0 To 9
Picture1.Print "数字" & i & ":" & c(i) & "次"
Next i
End Sub

Private Sub Form_Load()
Dim i As Integer
Command1.Caption = "统计"
Randomize Timer
Text1.Text = ""
For i = 1 To 30
Text1.Text = Text1.Text & Int(Rnd() * 10)
Next i
End Sub
Sub CountN(a(), count())
Dim i As Integer
For i = LBound(a) To UBound(a)
count(Val(a(i))) = count(Val(a(i))) + 1
Next i
End Sub