ASP Dictionary对象使用小结

<%
Dim oDic,aItems,aKeys
Set oDic = Server.CreateObject("Scripting.Dictionary")

'添加
oDic.Add "aaa",111
oDic.Add "bbb",222
oDic.Add "ccc",333
oDic.Add "ddd",444

'修改
If oDic.Exists("aaa") Then
    oDic.key("aaa") = "eee" 'key属性,只读
    oDic.item("eee") = 555 'item属性,可读写
End If

'列表
aKeys = oDic.Keys
aItems = oDic.Items
For i=0 To oDic.Count-1
    Response.Write(aKeys(i) & "," & aItems(i))
Next

'删除
Response.Write(oDic.Count)
oDic.Remove("eee") '从 Dictionary 对象中删除键和项目对
Response.Write(oDic.Count)
oDic.RemoveAll() '删除 Dictionary 对象中的所有键和项目对
Response.Write(oDic.Count)

Set oDic = Nothing
%>


评论: 0 | 引用: 0 | 查看次数: 4650
发表评论
登录后再发表评论!