asp 数组排序函数
[ 2007-02-05 04:15:55 | 作者: admin ]
p.s. 如果排序不对,看看是不是字符串的数组,而没有转化成数字
<%
Function Sort(ary)
Dim KeepChecking,I,FirstValue,SecondValue
KeepChecking = TRUE
Do Until KeepChecking = FALSE
KeepChecking = FALSE
For I = 0 to UBound(ary)
If I = UBound(ary) Then Exit For
If ary(I) > ary(I+1) Then
FirstValue = ary(I)
SecondValue = ary(I+1)
ary(I) = SecondValue
ary(I+1) = FirstValue
KeepChecking = TRUE
End If
Next
Loop
Sort = ary
End Function
ID="199,163,84,136,256,192,282,180,421,325,230,322,145,299,297,222,88,208,232,405,323,131,83,120,100,235,399,267,146,227,243,172,314,324,300,195,153,357,292,344,118,77,398,319,337,341,185,347,293,16"
ArrayID=split(ID,",")
Myarray=Sort(ArrayID)
'排序测试
For M=0 To Ubound(Myarray)
Response.Write Myarray(M) & "<br>" & vbCRLF
Next
%>
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=799
<%
Function Sort(ary)
Dim KeepChecking,I,FirstValue,SecondValue
KeepChecking = TRUE
Do Until KeepChecking = FALSE
KeepChecking = FALSE
For I = 0 to UBound(ary)
If I = UBound(ary) Then Exit For
If ary(I) > ary(I+1) Then
FirstValue = ary(I)
SecondValue = ary(I+1)
ary(I) = SecondValue
ary(I+1) = FirstValue
KeepChecking = TRUE
End If
Next
Loop
Sort = ary
End Function
ID="199,163,84,136,256,192,282,180,421,325,230,322,145,299,297,222,88,208,232,405,323,131,83,120,100,235,399,267,146,227,243,172,314,324,300,195,153,357,292,344,118,77,398,319,337,341,185,347,293,16"
ArrayID=split(ID,",")
Myarray=Sort(ArrayID)
'排序测试
For M=0 To Ubound(Myarray)
Response.Write Myarray(M) & "<br>" & vbCRLF
Next
%>

这篇日志没有评论。
此日志不可发表评论。