ASP 사전 개체
Dictionary 객체는 이름/값 쌍에 정보를 저장합니다.
더 많은 예
Dictionary 개체를 만든 다음 Exists 메서드를 사용하여 지정된 키가 있는지 확인하는 방법입니다.
을 반환하기 위해 Items 메서드를 사용하는 방법.
모든 키의 배열 반환 Keys 메서드를 사용하여
값 반환 Item 속성을 사용하여 항목 값을 반환하는 방법입니다.
설정 Key 속성을 사용하여 Dictionary 개체에 키를 설정하는 방법입니다.
수 반환 Count 속성을 사용하여 키/항목 쌍 수를 반환하는 방법.
사전 개체
Dictionary 객체는 이름/값 쌍(키 및 항목이라고 함)에 정보를 저장하는 데 사용됩니다. Dictionary 객체는 Arrays와 비슷해 보일 수 있지만 Dictionary 객체는 관련 데이터를 조작하는 데 더 바람직한 솔루션입니다.
사전과 배열 비교:
- 키는 Dictionary 객체의 항목을 식별하는 데 사용됩니다.
- Dictionary 개체의 크기를 변경하기 위해 ReDim을 호출할 필요가 없습니다.
- 사전에서 항목을 삭제할 때 나머지 항목은 자동으로 위로 이동합니다.
- 사전은 다차원일 수 없으며 배열은
- 사전에는 배열보다 더 많은 내장 함수가 있습니다.
- 사전은 무작위 요소에 자주 액세스할 때 배열보다 더 잘 작동합니다.
- 사전은 내용으로 항목을 찾는 데 배열보다 더 잘 작동합니다.
다음 예는 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"))
%>
Output:
The value of key gr is: Green
Dictionary 개체의 속성 및 메서드는 다음과 같습니다.
속성
Property | Description |
---|---|
CompareMode | Sets or returns the comparison mode for comparing keys in a Dictionary object |
Count | Returns the number of key/item pairs in a Dictionary object |
Item | Sets or returns the value of an item in a Dictionary object |
Key | Sets a new key value for an existing key value in a Dictionary object |
행동 양식
Method | Description |
---|---|
Add | Adds a new key/item pair to a Dictionary object |
Exists | Returns a Boolean value that indicates whether a specified key exists in the Dictionary object |
Items | Returns an array of all the items in a Dictionary object |
Keys | Returns an array of all the keys in a Dictionary object |
Remove | Removes one specified key/item pair from the Dictionary object |
RemoveAll | Removes all the key/item pairs in the Dictionary object |