VBScript篩選器函式



篩選器函式,基於特定的篩選器條件返回一個包含字串陣列子集的零基陣列。

語法

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_arrays.htm
廣告