当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP > ASP Dictionary

ASP
ASP 介绍
ASP Install
ASP 语法
ASP 变量
ASP Procedures
ASP Forms
ASP Cookies
ASP Session
ASP Application
ASP #include
ASP Global.asa
ASP Send e-mail
ASP Response
ASP Request
ASP Application
ASP Session
ASP Server
ASP Error
ASP FileSystem
ASP TextStream

ASP Dictionary


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

The Dictionary object is used to store information in name/value pairs (referred to as key and item)
Dictionary(字典对象)是用来存储名称或值的信息的(涉及到的内容注入一些关键字以及项目)


Examples
举例

Does a specified key exist?
查看制定的关键词是否存在
This example demonstrates how to first create a Dictionary object, and then use the Exists method to check if a specified key exists.
这个例子告诉我们如何创建一个Dictionary对象,然后使用Exists方法检查一个制定的关键词是否存在。

Return an array of all items
返回一个存储所有项目的数组
This example demonstrates how to use the Items method to return an array of all the items.
这个例子告诉我们如何使用Items方法返回一个存储所有项目的数组。

Return an array of all keys
返回一个存储所有关键词的数组
This example demonstrates how to use the Keys method to return an array of all the keys.
这个例子告诉我们如何使用Keys方法返回一个存储所有关键词的数组。

Return the value of an item
返回一个项目的值
This example demonstrates how to use the Item property to return the value of an item.
这个例子告诉我们如何使用Item属性返回一个项目的值。

Set a key
设置一个关键词
This example demonstrates how to use the Key property to set a key in a Dictionary object.
这个例子告诉我们如何使用Key属性设置一个Dictionary对象的关键词。

Return the number of key/item pairs
返回关键词或项目的数量
This example demonstrates how to use the Count property to return the number of key/item pairs.
这个例子告诉我们如何使用Count属性返回关键词或项目的数量。


The Dictionary Object
Dictionary(字典)对象

The Dictionary object is used to store information in name/value pairs (referred to as key and item). The Dictionary object might seem similar to Arrays, however, the Dictionary object is a more desirable solution to manipulate related data.
Dictionary(字典对象)是用来存储名称或值的信息的(涉及到的内容注入一些关键字以及项目)Dictionary对象可能与数组类似,然而,Dictionary对象的最大优点就是它可以解决对相关时间操作的问题。

Comparing Dictionaries and Arrays:
Dictionary(字典)与Arrays(数组)的比较:

  • Keys are used to identify the items in a Dictionary object 
    在Dictionary对象中,Keys(关键词)使用来定义items(项目)的。
  • You do not have to call ReDim to change the size of the Dictionary object
    你不需要使用ReDim指令来改变Dictionary对象的大小。
  • When deleting an item from a Dictionary, the remaining items will automatically shift up
    当你从一个Dictionary中删除一个项目时,保留的项目将会被自动转移。
  • Dictionaries cannot be multidimensional, Arrays can
    Dictionary只能是一维的,但Array(数组)可以是多维的。
  • Dictionaries have more built-in functions than Arrays
    Dictionary可以比Array拥有更多的内置函数。
  • Dictionaries work better than arrays on accessing random elements frequently
    Dictionary可以比Array更好的频繁访问随机元素。
  • Dictionaries work better than arrays on locating items by their content 
    Dictionary 可以比Array更好的定位item的内容。

The following example creates a Dictionary object, adds some key/item pairs to it, and retrieves the item value for the key gr:
下面的例子建立了一个Dictionary对象,并往其中添加了一些keys(关键词)以及items(项目),然后获取名为“gr”的item的值:

<%
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"))
%>

Output:

The value of key gr is: Green 

The Dictionary object's properties and methods are described below:
Dictionary对象的属性以及使用方法被描述如下:

Properties
属性

Property
属性
Description
具体描述
CompareMode Sets or returns the comparison mode for comparing keys in a Dictionary object
设置或返回一个Dictionary对象中的关键词的比较模式
Count Returns the number of key/item pairs in a Dictionary object
返回一个Dictionary对象中关键词或项目的数量
Item Sets or returns the value of an item in a Dictionary object
设置或返回Dictionary对象中一个item的值
Key Sets a new key value for an existing key value in a Dictionary object
为一个存在于Dictionary对象中的关键词设置一个新的值

Methods
方法

Method
方法
Description
具体描述
Add Adds a new key/item pair to a Dictionary object
往Dictionary对象中添加一个新的关键词或项目
Exists Returns a Boolean value that indicates whether a specified key exists in the Dictionary object
返回一个布林(“真、假”逻辑值)值,检查存在于一个Dictionary对象中的指定关键词是否存在
Items Returns an array of all the items in a Dictionary object
将存在于一个Dictionary对象中的所有items(项目)存储在一个数组中
Keys Returns an array of all the keys in a Dictionary object
将存在于一个Dictionary对象中的所有keys(关键词)存储在一个数组中
Remove Removes one specified key/item pair from the Dictionary object
从Dictionary对象中删除一个指定的keys(关键词)或items(项目)
RemoveAll Removes all the key/item pairs in the Dictionary object
从Dictionary对象中删除所有的keys(关键词)或items(项目)

评论 (0) All

登陆 | 还没注册?