日期:2008-07-15  浏览次数:21221 次

Aiyiweb.Com提示:指定的键存在吗?本例演示如何受首先创建一个Dictionary对象,然后使用Exists方法来检查指定的键能否存在。前往一个所有项目的数组:本例演示如何使用Items方法来前往所有项目的一个数组。前往一个所有键的数组:本例演示如何使用Keys方法来前往所有键的一个数组。前往

Dictionary 对象

指定的键存在吗?

本例演示如何受首先创建一个Dictionary对象,然后使用Exists方法来检查指定的键能否存在。

本实例代码如下:

<html>
<body>
<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "c", "China"
d.Add "i", "Italy"
if d.Exists("c")= true then
    Response.Write("键存在。")
else
    Response.Write("键不存在。")
end if
set d=nothing
%>
</body>
</html>

本文由爱易网任务室(http://www.Aiyiweb.Com)整理发布!转载请注明出处,谢谢!

本实例运转结果如下:

 键存在。

前往一个所有项目的数组

本例演示如何使用Items方法来前往所有项目的一个数组。

本实例代码如下:

<html>
<body>
<%
dim d,a,i,s
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "c", "China"
d.Add "i", "Italy"
Response.Write("<p>项目的值是:</p>")
a=d.Items
for i = 0 To d.Count -1
    s = s & a(i) & "<br>"
next
Response.Write(s)
set d=nothing
%>
</body>
</html>

本实例运转结果如下:

 项目的值是:
China
Italy

前往一个所有键的数组

本例演示如何使用Keys方法来前往所有键的一个数组。

本文是爱易网(http://www.Aiyiweb.Com)收集整理或者原创内容,转载请注明出处!

本实例代码如下:

<html>
<body>
<%
dim d,a,i,s
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "c", "China"
d.Add "i", "Italy"
Response.Write("<p>键的值是:</p>")
a=d.Keys
for i = 0 To d.Count -1
    s = s & a(i) & "<br>"
next
Response.Write(s)
set d=nothing
%>
</body>
</html>

本实例运转结果如下:

键的值是:
c
i

前往某个项目的值

本例演示如何使用Item属性来前往某个项目的值。

本实例代码如下:

<html>
<body>
<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "c", "China"
d.Add "i", "Italy"
Response.Write("项目 i 的值是:" & d.item("i"))
set d=nothing
%>
</body>
</html>

本实例运转结果如下:

项目 i 的值是:Italy

设置一个键

本例演示如何使用Key属性来在Dictionary对象中设置一个键。

本实例代码如下:

<html>
<body>
<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "c", "China"
d.Add "i", "Italy"
d.Key("i") = "it"
Response.Write("键 i 已设置为 it,其值是:" & d.Item("it"))
set d=nothing
%>
</body>
</html>

本实例运转结果如下:

键 i 已设置为 it,其值是:Italy

前往键/项目对的数目

本例演示如何使用Count属性来前往键/项目对的数目。

本实例代码如下:

<html>
<body>
<%
dim d, a, s, i
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "c", "China"
d.Add "i", "Italy"
Response.Write("key/item 对的数目是:" & d.Count)
set d=nothing
%>
</body>
</html>

本实例运转结果如下:

key/item