vbscript的Scripting.Dictionary创建了类似于Key索引对应Value值的字典对象,通过Key直接索引到指定的Value。
VBScript中Scripting.Dictionary使用示例如下:
代码如下:
Dim objDict
Set objDict = WSH.CreateObject("Scripting.Dictionary")
'' .Add(key, value)
objDict.Add "a", "value1"
objDict.Add "b", "value2"
objDict.Add "c", "value3"
''直接通过key=b索引到value2
WSH.Echo objDict.Item("b")
objDict.Remove "b" '' 删除索引b及其对应的值
'' 以下是遍历字典
Dim objKeys, objItems, i
objKeys = objDict.Keys
objItems = objDict.Items
For i = 0 To objDict.Count -1
WSH.Echo "Key=" & objKeys(i) &_
" AND Value="http://www.popasp.com/& objItems(i)
Next
'' 判断指定的key是否存在
If objDict.Exists("b") Then
WSH.Echo "Found it"
Else
WSH.Echo "Not Exists!"
End If
objDict.RemoveAll '' 清空字典内所有的key及其对应value
Set objDict = Nothing
11
22
33