VBScript Filter Function

Definition and Usage

The Filter function can return an array based on 0, which contains a subset of the string array based on a specific filtering condition.

Comments:If the Filter function cannot find a value that matches the value parameter, it will return an empty array.

Comments:An error will occur if the parameter inputstrings is null or not a one-dimensional array.

Syntax

Filter(inputstrings,value[,include[,compare]])
Parameter Description
inputstrings Mandatory. A one-dimensional string array to be searched.
value Required. The string to be searched.
include Optional. Boolean value specifying whether the returned substring contains Value. If Include is True, Filter will return a subset of the array that contains the substring Value. If Include is False, Filter will return a subset of the array that does not contain the substring Value.
compare Optional. Specifies the type of string comparison to be used.

The value of the parameter 'compare':

Constant Value Description
vbBinaryCompare 0 Execute binary comparison.
vbTextCompare 1 Execute text comparison.

Instance

Example 1

dim a(5),b
a(0)="Saturday"
a(1)="Sunday"
a(2)="Monday"
a(3)="Tuesday"
a(4)="Wednesday"
b=Filter(a,"n")
document.write(b(0))
document.write(b(1))
document.write(b(2))

Output:

Sunday
Monday
Wednesday

Example 2

dim a(5),b
a(0)="Saturday"
a(1)="Sunday"
a(2)="Monday"
a(3)="Tuesday"
a(4)="Wednesday"
b=Filter(a,"n",false)
document.write(b(0))
document.write(b(1))
document.write(b(2))

Output:

Saturday
Tuesday