當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


ASP Exists用法及代碼示例

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("<br>")
  
'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 

相關用法


注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 ASP Exists Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。