Count and insert unique values - Can this code be optimized?

前端 未结 3 1569
渐次进展
渐次进展 2021-01-26 18:09

I needed to generate an output from my Access database that was unavailable using standard functions. I did extensive searching, but when I found example code - it ultimately f

3条回答
  •  故里飘歌
    2021-01-26 18:37

    "Unique" means "Dictionary" in VBScript. So use one as in:

    >> Set d = CreateObject("Scripting.Dictionary")
    >> For Each c In Split("a b b b c c d")
    >>     If Not d.Exists(c) Then
    >>        d(c) = 1 + d.Count
    >>     End If
    >> Next
    >> For Each c In Split("a b b b c c d")
    >>     WScript.Echo c, d(c)
    >> Next
    >>
    a 1
    b 2
    b 2
    b 2
    c 3
    c 3
    d 4
    

    where "c 3" means: "c is the 3rd unique item found in the source collection".

提交回复
热议问题