加強陣列的功能.
使用範例:
<!--#include Virtual = "/inc/max.Array.Object.asp" -->
<%
dim a2
Set a2 = New maxArrayObject
'// 把字串轉成陣列
a2.fromString("3,1")
'// or 用下面這行指令:
' a2.item = array("3","1")
'// sort asc
' a2.sort()
' response.write a2.toString()
'// sort desc
' a2.fromString("1,3")
' a2.sortDesc()
' response.write a2.toString()
'// check item exist (附註: 數字3 及 字串 "3" 是不相等的)
' response.write "<br/>isExist:" & a2.isExist("3")
' response.write "<br/>isExist:" & a2.isExist(3)
' response.write "<br/>isExist:" & a2.isExist("9")
'// find item. (附註: find 會傳回一個 index)
' response.write "<br/>find 1:" & a2.find("1")
' response.write "<br/>find 3:" & a2.find("3")
'// compre two array, is array equal.
' dim a4
' a4 = a2.getArray()
' response.write "<br/>is array equal:" & a2.equal(a4)
'// append new item.
a2.append("5")
' response.write a2.toString()
'// insert "2" before "3"
' a2.insert "2", 1
'// or
a2.insert "2", a2.find("3")
'// append array, a6 陣列加到 a2 陣列後面.
' dim a6
' a6 = a2.getArray
' a2.appendArray(a6)
'// count item. 查詢某個值在陣列裡出現的次數.
' response.write "<br/>count item 1: " & a2.countItem("1")
'// delete item,
'// 先查詢 "1" 出現在 a2陣列裡, 再使用 a2.deleteIndex 刪除該值.
a2.delete("1")
'// delete from array, 用來一次刪除一堆的值.
dim deleteResult
dim deleteArraySet
set deleteResult = new maxArrayObject
deleteArraySet = array("4","5","6")
deleteResult.setArray(a2.deleteFromArray(deleteArraySet))
response.write "<br/>deleteResult to string: " & deleteResult.toString()
'// 附註: { 2 ,3 ,5 } - { 4 ,5 ,6 } = { 2 ,3 }
'// 計算加總.
' response.write "<br/>sum: " & a2.sum
'// 計算平均.
' response.write "<br/>average: " & a2.average
'// 存取陣列某一筆.
response.write "<br/>item 1: " & a2.item(0)
'// 輸出陣列內容.
response.write "<br/>to string: " & a2.toString()
%>
附件列表:
max.Array.Function.asp , 副程式.
max.Array.Object.asp , 物件化的程式.
附註:
如果您有在使用這個物件, 並有加強他的功能的話, 請再把您修改過的寄給我用, 謝謝.
沒有留言:
張貼留言