Dictionary 对象可以实现关联数组。项目(可以是任何形式的数据)被保存在数组中。每项都与唯一的键相关联。键值用于检索单个项目,通常是整数或字符串,但不能为数组。
Dim d '创建一个变量。
Set d = CreateObject("Scripting.Dictionary") '创建dictionary对象
'向 Dictionary 对象添加键和项目对
d.Add "a", "asp"
d.Add "b", "php"
d.Add "c", "jsp"
'如果在 Dictionary 对象中存在指定键,返回 True;如果不存在,返回 False
If d.Exists("c") Then
msg = "指定的键存在。"
Else
msg = "指定的键不存在。"
End If
'返回一个数组,其中包含有 Dictionary 对象中的所有项目
a = d.Items '获取项目。
For i = 0 To d.Count -1 '循环使用数组。
s = s & a(i) & "<BR>" '创建返回字符串。
Next
'返回一数组,其中包含有 Dictionary 对象的所有现存键
a = d.Keys '获取键。
For i = 0 To d.Count -1 '循环使用数组。
s = s & a(i) & "<BR>" '返回结果。
Next
'从 Dictionary 对象中删除键和项目对
a = d.Remove("b")
'RemoveAll 方法删除 Dictionary 对象中的所有键和项目对
a = d.RemoveAll
Dim d '创建一个变量。
Set d = CreateObject("Scripting.Dictionary") '创建dictionary对象
'向 Dictionary 对象添加键和项目对
d.Add "a", "asp"
d.Add "b", "php"
d.Add "c", "jsp"
'如果在 Dictionary 对象中存在指定键,返回 True;如果不存在,返回 False
If d.Exists("c") Then
msg = "指定的键存在。"
Else
msg = "指定的键不存在。"
End If
'返回一个数组,其中包含有 Dictionary 对象中的所有项目
a = d.Items '获取项目。
For i = 0 To d.Count -1 '循环使用数组。
s = s & a(i) & "<BR>" '创建返回字符串。
Next
'返回一数组,其中包含有 Dictionary 对象的所有现存键
a = d.Keys '获取键。
For i = 0 To d.Count -1 '循环使用数组。
s = s & a(i) & "<BR>" '返回结果。
Next
'从 Dictionary 对象中删除键和项目对
a = d.Remove("b")
'RemoveAll 方法删除 Dictionary 对象中的所有键和项目对
a = d.RemoveAll