非常教程

ASP参考手册

ASP Dictionary 对象

ASP Dictionary 对象

ASP Dictionary 对象


Dictionary 对象用于在名称/值对中存储信息。


ASP Dictionary 对象

尝试一下 - 实例

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

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

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

返回一个项目的值
本例演示如何使用 Item 属性来返回一个项目的值。

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

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


Dictionary 对象

Dictionary 对象用于在名称/值对(等同于键和项目)中存储信息。Dictionary 对象看似比数组更为简单,然而,Dictionary 对象却是更令人满意的处理关联数据的解决方案。

比较 Dictionaries 和数组:

  • 键用于识别 Dictionary 对象中的项目
  • 您无需调用 ReDim 来改变 Dictionary 对象的尺寸
  • 当从 Dictionary 中删除一个项目时,其余的项目会自动上移
  • Dictionary 不是多维,而数组是多维
  • Dictionary 比数组带有更多的内建函数
  • Dictionary 在频繁地访问随机元素时,比数组工作得更好
  • Dictionary 在根据它们的内容定位项目时,比数组工作得更好

下面的实例创建了一个 Dictionary 对象,并向对象添加了一些键/项目对,然后取回了键 gr 的项目值:

<%
Dim d
Set d=Server.CreateObject("Scripting.Dictionary")
d.Add "re","Red"
d.Add "gr","Green"
d.Add "bl","Blue"
d.Add "pi","Pink"
Response.Write("The value of key gr is: " & d.Item("gr"))
%>

输出:

The value of key gr is: Green

Dictionary 对象的属性和方法描述如下:

属性

属性 描述
CompareMode 设置或返回用于在 Dictionary 对象中比较键的比较模式。
Count 返回 Dictionary 对象中键/项目对的数目。
Item 设置或返回 Dictionary 对象中一个项目的值。
Key 为 Dictionary 对象中已有的键值设置新的键值。

方法

方法 描述
Add 向 Dictionary 对象添加新的键/项目对。
Exists 返回一个布尔值,这个值指示指定的键是否存在于 Dictionary 对象中。
Items 返回 Dictionary 对象中所有项目的一个数组。
Keys 返回 Dictionary 对象中所有键的一个数组。
Remove 从 Dictionary 对象中删除指定的键/项目对。
RemoveAll 删除 Dictionary 对象中所有的键/项目对。

ASP Dictionary 对象

ASP目录

1.ASP 简介
2.ASP 教程
3.在自己的 PC 上运行 ASP
4.ASP Session 对象
5.ASP Cookies
6.ASP 表单
7.ASP 程序
8.ASP 变量
9.ASP 语法
10.ASP Session 对象
11.ASP Application 对象
12.ASP Request 对象
13.ASP Response 对象
14.ASP 使用 CDOSYS 发送电子邮件
15.ASP Global.asa
16.ASP 引用文件
17.ASP Application 对象
18.ASP ASPError 对象
19.ASP Server 对象
20.ASP FileSystem 对象
21.ASP ADO
22.ASP Dictionary 对象
23.ASP Folder 对象
24.ASP File 对象
25.ASP Drive 对象
26.ASP TextStream 对象
27.ASP Content Linking
28.ASP Browser Capabilities
29.ASP AdRotator
30.ASP 实例
31.ASP 总结
32.ASP 快速参考
33.AJAX 数据库
34.ASP – AJAX 与 ASP
35.ASP Charset 属性
36.ASP CacheControl 属性
37.ASP Buffer 属性
38.ASP Cookies 集合
39.ASP Clear 方法
40.ASP BinaryWrite 方法
41.ASP AppendToLog 方法
42.ASP AddHeader 方法
43.ASP Status 属性
44.ASP Pics 属性
45.ASP IsClientConnected 属性
46.ASP ExpiresAbsolute 属性
47.ASP Expires 属性
48.ASP ContentType 属性
49.ASP BinaryRead 方法
50.ASP TotalBytes 属性
51.ASP ServerVariables 集合
52.ASP QueryString 集合
53.ASP Form 集合
54.ASP Cookies 集合
55.ASP Write 方法
56.ASP Redirect 方法
57.ASP Flush 方法
58.ASP End 方法
59.ASP LCID 属性
60.ASP CodePage 属性
61.ASP StaticObjects 集合
62.ASP Contents 集合
63.ASP Application_OnStart 和 Application_OnEnd 事件
64.ASP Lock 和 Unlock 方法
65.ASP Contents.RemoveAll 方法
66.ASP Contents.Remove 方法
67.ASP StaticObjects 集合
68.ASP Contents 集合
69.ASP GetLastError 方法
70.ASP Execute 方法
71.ASP CreateObject 方法
72.ASP ScriptTimeout 属性
73.ASP Session_OnStart 和 Session_OnEnd 事件
74.ASP Contents.RemoveAll 方法
75.ASP Contents.Remove 方法
76.ASP Abandon 方法
77.ASP Timeout 属性
78.ASP SessionID 属性
79.ASP CreateFolder 方法
80.ASP CopyFolder 方法
81.ASP CopyFile 方法
82.ASP BuildPath 方法
83.ASP Drives 属性
84.ASP ASPError 对象的属性
85.ASP URLEncode 方法
86.ASP Transfer 方法
87.ASP MapPath 方法
88.ASP HTMLEncode 方法
89.ASP GetDriveName 方法
90.ASP GetDrive 方法
91.ASP GetBaseName 方法
92.ASP GetAbsolutePathName 方法
93.ASP FolderExists 方法
94.ASP FileExists 方法
95.ASP DriveExists 方法
96.ASP DeleteFolder 方法
97.ASP DeleteFile 方法
98.ASP CreateTextFile 方法
99.ASP OpenTextFile 方法
100.ASP MoveFolder 方法