Grouping an array in classic asp / vbscript?

Soldato
Joined
31 May 2006
Posts
4,239
Location
127.0.0.1
I have an array in ASP that looks like this:

Code:
3,5,7,7,3,2,3

What I want to do is group them together with a count so I would have:

Code:
Number  Count
2       1
3       3
5       1
7       2

Is this possible? If so how? Using a temp table in SQL?
 
Thanks for that. That is what I would use to store the groupings perhaps but is there a way to group the original array entries into a multi-dimensional array?
 
I was given the answer on another forum:

Code:
<%
    dim ar
    ar = array(3,5,7,7,3,2,3)

    dim dictArray

    set dictArray = server.CreateObject("Scripting.Dictionary")

    for each i in ar
        if dictArray.exists( i ) then
            dictArray(i) = dictArray(i) + 1
        else
            dictArray(i) = 1
        end if
    next
%>

<%
    for each i in dictArray
        response.write( i & " : " & dictArray(i) & "<br />")
    next
 %>
 
Back
Top Bottom