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
广告