当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP实例教程:Dictionary对象

ASP
asp #include命令
推荐下天枫常用ASP函数封装,推荐大家使用
asp最简单最实用的计数器
用asp实现的iframe批量替换工具
ASPWebPack 代码 提供下载
asp分页生成html的程序脚本代码
比较不错的asp单表单字段多条件查询
asp下用replace非正则实现代码运行功能的代码
UpdatePanel触发javascript脚本的方法附代码
生成EAN13标准的条形码的ASP代码实例
asp空间奸商查询系统
ASPWebPack(整站文件备份系统) v1.0.2 黑客也用
ASP+FSO可视化目录编历(可增、删、改)下载
提高ASP效率的五大技巧
ASP生成随机字符串(数字+大小写字母)的代码
ASP下存储过程编写入门全接触
利用 cache 做对比静态页的网页技术
ASP生成静态文件编码为UTF-8格式的HTML文件
ASP下的两个防止SQL注入式攻击的Function
asp下的风讯用的SQL通用防注入模块提供了

ASP实例教程:Dictionary对象


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 88 ::
收藏到网摘: n/a

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.ruanchen.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方法来返回所有键的一个数组。

本实例代码如下:

<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 对的数目是:2