ASP 使用Filter函數(shù)來檢索數(shù)組的實現(xiàn)代碼
更新時間:2011年06月18日 23:43:50 作者:
在VBScript中有Filter這個函數(shù)可以用來對數(shù)組進行過濾,并返回原數(shù)組的一個子集數(shù)組。
語法說明:
Filter 函數(shù)
返回下標從零開始的 數(shù)組,其中包含以特定過濾條件為基礎的字符串數(shù)組的子集。
Filter(InputStrings, Value[, Include[, Compare]])
參數(shù)
InputStrings
必選項。一維數(shù)組,要在其中搜索字符串。
Value
必選項。要搜索的字符串。
Include
可選項。Boolean 值,指定返回的子字符串是否包含 Value。如果 Include 為 True,F(xiàn)ilter 將返回包含子字符串 Value 的數(shù)組子集。如果 Include 為 False,F(xiàn)ilter 將返回不包含子字符串 Value 的數(shù)組子集。
Compare
可選項。數(shù)字值指出使用的比較字符串 類型.請參閱值設置部分.
設置
Compare 參數(shù)可以有以下值:
常數(shù)
值
描述
vbBinaryCompare
0
執(zhí)行二進制比較。
vbTextCompare
1
執(zhí)行文本比較。
說明
如果在 InputStrings 中沒有找到與 Value 匹配的值,F(xiàn)ilter 將返回空數(shù)組。如果 InputStrings 為 Null 或者不是一維數(shù)組,則會發(fā)生錯誤。
由 Filter 函數(shù)返回的數(shù)組僅包含足以包含匹配項數(shù)目的元素。
下面例子利用 Filter 函數(shù)返回包含搜索條件 "Mon" 的數(shù)組:
Dim MyIndex
Dim MyArray (3)
MyArray(0) = "Sunday"
MyArray(1) = "Monday"
MyArray(2) = "Tuesday"
MyIndex = Filter(MyArray, "Mon") 'MyIndex(0) 包含 "Monday"。
在紅色的位置需要注意一下,MyIndex是一個數(shù)組!~
Dim MyIndex,IndexItem
Dim MyArray(2)
MyArray(0) = "Sunday"
MyArray(1) = "Monday"
MyArray(2) = "Monday"
MyIndex = Filter(MyArray,"Tuesday")
For IndexItem = 0 To UBound(MyIndex)
Response.Write MyIndex(Monday)&"<br />"
Next
Filter 函數(shù)
返回下標從零開始的 數(shù)組,其中包含以特定過濾條件為基礎的字符串數(shù)組的子集。
Filter(InputStrings, Value[, Include[, Compare]])
參數(shù)
InputStrings
必選項。一維數(shù)組,要在其中搜索字符串。
Value
必選項。要搜索的字符串。
Include
可選項。Boolean 值,指定返回的子字符串是否包含 Value。如果 Include 為 True,F(xiàn)ilter 將返回包含子字符串 Value 的數(shù)組子集。如果 Include 為 False,F(xiàn)ilter 將返回不包含子字符串 Value 的數(shù)組子集。
Compare
可選項。數(shù)字值指出使用的比較字符串 類型.請參閱值設置部分.
設置
Compare 參數(shù)可以有以下值:
常數(shù)
值
描述
vbBinaryCompare
0
執(zhí)行二進制比較。
vbTextCompare
1
執(zhí)行文本比較。
說明
如果在 InputStrings 中沒有找到與 Value 匹配的值,F(xiàn)ilter 將返回空數(shù)組。如果 InputStrings 為 Null 或者不是一維數(shù)組,則會發(fā)生錯誤。
由 Filter 函數(shù)返回的數(shù)組僅包含足以包含匹配項數(shù)目的元素。
下面例子利用 Filter 函數(shù)返回包含搜索條件 "Mon" 的數(shù)組:
復制代碼 代碼如下:
Dim MyIndex
Dim MyArray (3)
MyArray(0) = "Sunday"
MyArray(1) = "Monday"
MyArray(2) = "Tuesday"
MyIndex = Filter(MyArray, "Mon") 'MyIndex(0) 包含 "Monday"。
在紅色的位置需要注意一下,MyIndex是一個數(shù)組!~
復制代碼 代碼如下:
Dim MyIndex,IndexItem
Dim MyArray(2)
MyArray(0) = "Sunday"
MyArray(1) = "Monday"
MyArray(2) = "Monday"
MyIndex = Filter(MyArray,"Tuesday")
For IndexItem = 0 To UBound(MyIndex)
Response.Write MyIndex(Monday)&"<br />"
Next
您可能感興趣的文章:
- asp取得數(shù)組中的最大值的方法
- asp下使用數(shù)組存放數(shù)據(jù)的代碼
- asp 得到動態(tài)數(shù)組中元素的個數(shù)
- asp.net 數(shù)組中字符串替換的幾種方式
- asp 動態(tài)數(shù)組 提供Add、Insert、Remove、RemoveAt、Search等方法。
- asp.net 字符串、二進制、編碼數(shù)組轉換函數(shù)
- asp.net通過js實現(xiàn)Cookie創(chuàng)建以及清除Cookie數(shù)組的代碼
- asp textarea 多行數(shù)組分割處理方法
- asp 數(shù)組 重復刪除函數(shù)(腳本之家增強版)
- ASP 過濾數(shù)組重復數(shù)據(jù)函數(shù)(加強版)
- asp數(shù)組的使用介紹
- Asp與JS的數(shù)組和字符串下標介紹
- asp中使用redim、preserve創(chuàng)建動態(tài)數(shù)組實例
- ASP定義數(shù)組方法的技巧
相關文章
asp(JavaScript)自動判斷網(wǎng)頁編碼并轉換的代碼
asp轉換網(wǎng)頁編碼的代碼,用正則匹配頁面的編碼聲明是gb2312還是別的,然后輸出。2010-06-06asp實現(xiàn)獲取MSSQL數(shù)據(jù)庫表指定條件行數(shù)的函數(shù)
這篇文章主要介紹了asp實現(xiàn)獲取MSSQL數(shù)據(jù)庫表指定條件行數(shù)的函數(shù)的的相關資料,需要的朋友可以參考下2015-03-03