有类似如下的字符串
111,222,333,444,111,999,ABC,ABC,cde,333....想要分类统计每一个用,分隔的子串出现的字数想要得到如下结果:
出现一次的串有:
222,444,999,cde
出现二次的串有:
111,333,ABC
....
出现N次的串有:
...
111,222,333,444,111,999,ABC,ABC,cde,333....想要分类统计每一个用,分隔的子串出现的字数想要得到如下结果:
出现一次的串有:
222,444,999,cde
出现二次的串有:
111,333,ABC
....
出现N次的串有:
...
Dim a() As String
s = "111,222,333,444,111,999,ABC,ABC,cde,333,444,222,444,333"
a = Split(s, ",")这样就可以将s分解为以逗号分割的字符串数组,然后你就可以统计每个数组出现的次数了。
Dim s As String
Dim a() As String
'Dim c As New
Dim c As New Scripting.Dictionary
Dim i As Integer
Dim o
s = "111,222,333,444,111,999,ABC,ABC,cde,333,444,222,444,333"
a = Split(s, ",")
For i = LBound(a) To UBound(a)
If (c.Exists(a(i))) Then
c.Item(a(i)) = c.Item(a(i)) + 1
Else
c.Add a(i), 1
End If
Next i
For i = 0 To c.Count - 1
Debug.Print c.Keys(i), c.Items(i)
Next i
End Sub就可以实现你要的效果了。