VBScript » Functions » Filter

Version: 1.0

Syntax:
Filter(String, Substring, Include,Compare)
String
The String argument is the name of a zero-based string array.
Substring
The Substring argument is the pattern of one or more characters that are searched for in the array.
Include
The optional Include argument must only be True or False. If True, the returned array will only consist of the values that contain the search pattern. If False, the returned array will only consist of the values that do not contain the search pattern.
Compare
The optional Compare argument must only use either the constant or value from the Comparison Constants table.

The Filter function searches the elements of a zero-based array, to match a pattern of one or more characters, and creates a new array, either with or without the elements containing the matched pattern.

You can create a zero-based string array by using the Split function. The Join function is used to reassemble the string after applying the Filter function.

Comparison Constants

CONSTANT VALUE DESCRIPTION
VBBinaryCompare 0 Binary comparison
VBTextCompare 1 Text Comparison
VBDataBaseCompare 2 Compare information inside database

Examples

Code:
<% myarray = Split("How now purple cow?") %>
<% myfilterarray = Filter(myarray, "ow") %>
<% =Join(myfilterarray) %>
Output:
How now cow?
Language(s): VBScript
Code:
<% myarray = Split("How now purple cow?") %>
<% myfilterarray = Filter(myarray, "ow", True) %>
<% =Join(myfilterarray) %>
Output:
How now cow?
Language(s): VBScript
Code:
<% myarray = Split("How now purple cow?") %>
<% myfilterarray = Filter(myarray, "ow", False) %>
<% =Join(myfilterarray) %>
Output:
purple
Language(s): VBScript
Code:
<% myarray = Split("How now purple cow?") %>
<% myfilterarray = Filter(myarray, "OW", True, 0) %>
<% =Join(myfilterarray) %>
Output:
(No output, because no match)
Explanation:

In the example, by using VBBinaryCompare, or 0, for the Compare argument, all upper/lower case differences are obeyed in the search.

Language(s): VBScript
Code:
<% myarray = Split("How now purple cow?") %>
<% myfilterarray = Filter(myarray, "OW", True, VBTextCompare) %>
<% =Join(myfilterarray) %>
Output:
How now cow?
Explanation:

In the example, by using VBTextCompare, or 1, for the Compare argument, all upper/lower case differences are ignored in the search.

Language(s): VBScript

See Also: