VBScript Filter Function


Filter :

A Filter Function, which returns a zero-based array that contains a subset of a string array based on a specific filter criteria.

Syntax :

  1. inputstrings, a Required parameter. This parameter corresponds to the array of strings to be searched.

  2. value, a Required Parameter. This parameter corresponds to the string to search for against the inputstrings parameter.

  3. include, an Optional Parameter. This is a Boolean value, which indicates whether or not to return the substrings that include or exclude.

  4. compare, an Optional Parameter. This Parameter describes what string comparison method to be used.

    • 0 = vbBinaryCompare - Performs a binary comparison

    • 1 = vbTextCompare - Performs a textual comparison

Example :

<!DOCTYPE html>
<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 />")

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

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


When the above code is saved as .HTML and executed in Internet Explorer, it produces the following result:

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