This article mainly introduces examples of using Scripting.Dictionary dictionary objects in asp. This article includes operations such as creation, assignment, traversal, and KEY judgment. Friends in need can refer to it.
Scripting.Dictionary of vbscript creates a dictionary object similar to the Key index corresponding to the Value value, and directly indexes to the specified Value through the Key.
Examples of using Scripting.Dictionary in VBScript are as follows:
Copy the code code as follows:Dim objDict
Set objDict = WSH.CreateObject(Scripting.Dictionary)
' .Add(key, value)
objDict.Add a, value1
objDict.Add b, value2
objDict.Add c, value3
'Index directly to value2 through key=b
WSH.Echo objDict.Item(b)
objDict.Remove b 'Delete index b and its corresponding value
'The following is a dictionary traversal
Dim objKeys, objItems, i
objKeys = objDict.Keys
objItems = objDict.Items
For i = 0 To objDict.Count -1
WSH.Echo Key= & objKeys(i) &_
AND Value= & objItems(i)
Next
' Determine whether the specified key exists
If objDict.Exists(b) Then
WSH.Echo Found it
Else
WSH.Echo Not Exists!
End If
objDict.RemoveAll ' Clear all keys and their corresponding values in the dictionary
Set objDict = Nothing