ASP 存在方法
ASP Exists 方法用于返回一个布尔值,如果指定的键存在则返回 true,否则返回 false。
句法:
DictionaryObject.Exists(key)
参数:此方法有一个参数,如上所述并在下面讨论:
- Key:指定要在字典中查找的键值的名称。
示例:下面的代码演示了 ASP Dictionary.Exists 方法。
ASP
<%
dim dict
'Create a new dictionary
set dict=Server.CreateObject("Scripting.Dictionary")
'Add values to the dictionary
dict.Add "g","geeks"
dict.Add "p","placements"
dict.Add "c","competitive"
'Check if the key exists in the dictionary
if dict.Exists("g")=true then
Response.Write("The 'g' key exists in the dictionary")
else
Response.Write("The 'g' key does not exist in the dictionary")
end if
Response.Write("
")
'Check for another key in the dictionary
if dict.Exists("m")=true then
Response.Write("The 'm' key exists in the dictionary")
else
Response.Write("The 'm' key does not exist in the dictionary")
end if
set dict=nothing
%>
输出:
The 'g' key exists in the dictionary
The 'm' key does not exist in the dictionary