回复 6 楼 vbhello
想了好半天,好象不需要排序这么复杂的,用一个二维数组分别记录字符串和出现的次数就行了,代码如下:
Private Sub Command1_Click()
Dim s As String, a() As String, b() As String, i As Integer, j As Integer, k As Integer
s = "c,4,k" & vbCrLf & _
"m,3,e" & vbCrLf & _
"9,f,s" & vbCrLf & _
"2,5,3" & vbCrLf & _
"2,5,3" & vbCrLf & _
"9,f,s" & vbCrLf & _
"2,5,3"
a = Split(s, vbCrLf)
ReDim b(UBound(a), 1)
k = 0
For i = 0 To UBound(a)
For j = k To 0 Step -1
If a(i) = b(j, 0) Then
b(j, 1) = Val(b(j, 1)) + 1
Exit For
End If
Next
If j < 0 Then
b(k, 0) = a(i)
b(k, 1) = 1
k = k + 1
End If
Next
Me.Cls
For i = 0 To k - 1
Print b(i, 0) & "出现" & b(i, 1) & "次"
Next
End Sub
图片附件: 游客没有浏览图片的权限,请
登录 或
注册