VB有关问题:字符串内容出现次数的统计方法
VB问题:字符串内容出现次数的统计方法
有这样一个字串:
"01 10 02 02 01 05 04 05 05 10 05 10 "
我想统计每个数字的出现次数,结果最好如下:
01 **
02 **
03
04 *
05 **
06
07
08
10 ***
谢谢
数字范围是10以内
------解决方案--------------------
Option Explicit
Private Sub Form_Load()
Dim ACount(99) As Integer
Dim iLoop As Integer, iTemp As Integer
Dim sData As String
sData = "01 10 02 02 01 05 04 05 05 10 05 10 "
For iLoop = 0 To 99
ACount(iLoop) = 0
Next iLoop
For iLoop = 0 To Len(sData) \ 3
iTemp = CInt(Mid(sData, iLoop * 3 + 1, 2))
ACount(iTemp) = ACount(iTemp) + 1
Next iLoop
For iLoop = 0 To 99
If ACount(iLoop) > 0 Then
Debug.Print Right( "0 " & iLoop, 2); ACount(iLoop)
End If
Next iLoop
End
End Sub
有这样一个字串:
"01 10 02 02 01 05 04 05 05 10 05 10 "
我想统计每个数字的出现次数,结果最好如下:
01 **
02 **
03
04 *
05 **
06
07
08
10 ***
谢谢
数字范围是10以内
------解决方案--------------------
Option Explicit
Private Sub Form_Load()
Dim ACount(99) As Integer
Dim iLoop As Integer, iTemp As Integer
Dim sData As String
sData = "01 10 02 02 01 05 04 05 05 10 05 10 "
For iLoop = 0 To 99
ACount(iLoop) = 0
Next iLoop
For iLoop = 0 To Len(sData) \ 3
iTemp = CInt(Mid(sData, iLoop * 3 + 1, 2))
ACount(iTemp) = ACount(iTemp) + 1
Next iLoop
For iLoop = 0 To 99
If ACount(iLoop) > 0 Then
Debug.Print Right( "0 " & iLoop, 2); ACount(iLoop)
End If
Next iLoop
End
End Sub