網上搜到的代碼,千篇一律是這個
FunctionSort(ary)
DimKeepChecking,I,FirstValue,SecondValue
KeepChecking=TRUE
DoUntilKeepChecking=FALSE
KeepChecking=FALSE
ForI=0toUBound(ary)
IfI=UBound(ary)ThenExitFor
Ifary(I)>ary(I+1)Then
FirstValue=ary(I)
SecondValue=ary(I+1)
ary(I)=SecondValue
ary(I+1)=FirstValue
KeepChecking=TRUE
EndIf
Next
Loop
Sort=ary
EndFunction
存在錯誤。 。 。 。 。 。
測試一下就知道
s="11,3,1"
s=sort(split(s,","))
fori=0toubound(s)
response.writes(i)&"<br>"
next
打印結果是
1
11
3
正確的function是:
functionsort(ary)
ck=true
doUntilck=false
ck=false
Forf=0toUBound(ary)-1
ifclng(ary(f))>clng(ary(f+1))then
v1=clng(ary(f))
v2=clng(ary(f+1))
ary(f)=v2
ary(f+1)=v1
ck=true
endif
next
loop
sort=ary
endfunction
就差在一個clng()
但好笑的是,有些數組,用那個錯誤的sort函數是可以排正確的。