ÄúµÄλÖãºÑ°ÃÎÍøÊ×Ò³£¾±à³ÌÀÖÔ°£¾VBScript£¾VBScript


objects constants operators statements functions properties methods






FUNCTION:  Filter( )

Filter(String, Substring, Include,Compare)

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.


There are two mandatory arguments.

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.

Code:
<% myarray = Split("How now purple cow?") %>
<% myarray = Filter(myarray, "ow")) %>
<% =Join(myarray) %>

Output:
How now cow?

There are two optional arguments.

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.

Code:
<% myarray = Split("How now purple cow?") %>
<% myarray = Filter(myarray, "ow", True) %>
<% =Join(myarray) %>

Output:
How now cow?

Code:
<% myarray = Split("How now purple cow?") %>
<% myarray = Filter(myarray, "ow", False) %>
<% =Join(myarray) %>

Output:
purple

Compare

The optional Compare argument must only use either the constant or value of the COMPARISON CONSTANTS.

CONSTANTVALUEDESCRIPTION
VBBinaryCompare0Binary comparison
VBTextCompare1Text Comparison
VBDataBaseCompare2Compare information inside database

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

Code:
<% myarray = Split("How now purple cow?") %>
<% myarray = Filter(myarray, "OW", True, 0) %>
<% =Join(myarray) %>

Output:
(No output, because no match)

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

Code:
<% myarray = Split("How now purple cow?") %>
<% myarray = Filter(myarray, "OW", True, VBTextCompare) %>
<% =Join(myarray) %>

Output:
How now cow?