s_array = split(a3,";") for i = 0 to ubound(s_array) for j=i+1 to ubound(s_array) if getSPName(s_array(i)) = getSPName(s_array(j)) then Nums = Nums + Cint(getSPNum(s_array(j))) end if next next
s_array = split(a3,";") for i = 0 to ubound(s_array) for j=i+1 to ubound(s_array) if getSPName(s_array(i)) = getSPName(s_array(j)) then Nums = Nums + Cint(getSPNum(s_array(j))) end if next
redim Preserve result(p) result(p) = getSPName(s_array(i)) "=" Nums p=p+1 next
這個里面勢必會遇到這樣的一個情況:當a3數(shù)組中的其后的某一元素總會與之前比較的相同的元素進行了運算,所以該元素就不能計入 for i = 0 to ubound(s_array)內的result(p) = getSPName(s_array(i)) "=" Nums動態(tài)數(shù)組中去。
s_array = split(a3,";") for i = 0 to ubound(s_array) for j=i+1 to ubound(s_array) if getSPName(s_array(i)) = getSPName(s_array(j)) then Nums = Nums + Cint(getSPNum(s_array(j))) end if
redim Preserve ID(q) ID(q) = j q = q + 1 next
redim Preserve result(p) result(p) = getSPName(s_array(i)) "=" Nums p=p+1 next
function IsInID(j) dim x IsInID = false for each x in ID if x = j then IsInID = true exit function End if Next end function
主要函數(shù)為
function mainhb(s) s_array = split(s,";") for i = 0 to ubound(s_array) if not IsInID(i) then Nums = getSPNum(s_array(i)) for j=i+1 to ubound(s_array) if getSPName(s_array(i)) = getSPName(s_array(j)) then Nums = Nums + Cint(getSPNum(s_array(j))) redim Preserve ID(q) ID(q) = j q = q + 1 end if next
redim Preserve result(p) result(p) = getSPName(s_array(i)) "=" Nums p = p + 1 end if next
for each x in result mainhb=mainhbx";" next end function
整體函數(shù)為
% dim result() dim ID() dim p , q , Nums
p=0 q= 0 Nums = 0
redim Preserve ID(q) ID(q) = ""
s = "sp4=33;sp2=20;sp1=34;sp3=2;sp2=3;sp4=4;" s = left(s,len(s)-1) response.write mainhb(s)
function mainhb(s) s_array = split(s,";") for i = 0 to ubound(s_array) if not IsInID(i) then Nums = getSPNum(s_array(i)) for j=i+1 to ubound(s_array) if getSPName(s_array(i)) = getSPName(s_array(j)) then Nums = Nums + Cint(getSPNum(s_array(j))) redim Preserve ID(q) ID(q) = j q = q + 1 end if next
redim Preserve result(p) result(p) = getSPName(s_array(i)) "=" Nums p = p + 1 end if 'Nums = 0 next
for each x in result mainhb=mainhbx";" next end function
Function getSPName(sp) getSPName = split(sp,"=")(0) End Function
Function getSPNum(sp) getSPNum = split(sp,"=")(1) end function
function IsInID(j) dim x IsInID = false for each x in ID if x = j then IsInID = true exit function End if Next end function %>