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


VBScript Filter用法及代碼示例


一個過濾函數,它返回一個從零開始的數組,其中包含基於特定過濾條件的字符串數組的子集。

用法

Filter(inputstrings,value[,include[,compare]]) 
  • inputstrings, 必需參數。該參數對應於要搜索的字符串數組。

  • value, 必需參數。此參數對應於要針對 inputstrings 參數搜索的字符串。

  • include,一個可選參數。這是一個布爾值,指示是否返回包含或排除的子字符串。

  • compare,一個可選參數。此參數描述要使用的字符串比較方法。

    • 0 = vbBinaryCompare - 執行二進製比較

    • 1 = vbTextCompare - 執行文本比較

示例

<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         a = array("Red","Blue","Yellow")
         b = Filter(a,"B")
         c = Filter(a,"e")
         d = Filter(a,"Y")

         For each x in b
           Document.write("The Filter result 1:" & x & "<br />")
         Next

         For each y in c
           Document.write("The Filter result 2:" & y & "<br />")
         Next

         For each z in d
           Document.write("The Filter result 3:" & z & "<br />")
         Next

      </script>
   </body>
</html>

當上麵的代碼保存為 .HTML 並在 Internet Explorer 中執行時,它會產生以下結果——

The Filter result 1:Blue
The Filter result 2:Red
The Filter result 2:Blue
The Filter result 2:Yellow
The Filter result 3:Yellow

相關用法


注:本文由純淨天空篩選整理自 VBScript Filter Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。