我有一个用经典asp编写的二维数组,比如
1-5
1-3
2-5
我需要以下格式的数组输出
1-8
2-5
请帮帮我
发布于 2013-01-10 20:53:15
您需要一个字典来汇总按col1值分组的col2值。如下所示:
ReDim aIn(2, 1)
aIn(0, 0) = 1 : aIn(0, 1) = 5
aIn(1, 0) = 1 : aIn(1, 1) = 3
aIn(2, 0) = 2 : aIn(2, 1) = 5
Dim dicX : Set dicX = CreateObject("Scripting.Dictionary")
Dim i
For i = LBound(aIn, 1) To UBound(aIn, 1)
dicX(aIn(i, 0)) = dicX(aIn(i, 0)) + aIn(i, 1)
Next
ReDim aOut(dicX.Count - 1, 1)
For i = LBound(aOut, 1) To UBound(aOut, 1)
aOut(i, 0) = dicX.Keys()(i)
aOut(i, 1) = dicX(aOut(i, 0))
Next
For i = LBound(aOut, 1) To UBound(aOut, 1)
WScript.Echo aOut(i, 0), aOut(i, 1)
Next
输出:
======
1 8
2 5
======
https://stackoverflow.com/questions/14256440
复制相似问题