VBScript FilterFunction


VBScript 参考手册Complete VBScript Reference

The Filter function returns a zero-based array that contains a subset of a string array based on a specific filter condition.

Note:If no matching values for the value parameter are found, the Filter function returns an empty array.

Note:An error occurs if the inputstrings parameter is Null or is not a one-dimensional array.

Syntax

Filter(inputstrings,value[,include[,compare]])

Parameter Description
inputstrings Required. A one-dimensional array of strings to be searched.
value Required. The string to search for.
include Optional. A Boolean value indicating whether the returned substring includes Value. If Include is True, Filter returns the subset of the array that contains the substring Value. If Include is False, Filter returns the subset of the array that does not contain the substring Value. The default is True.
compare Optional. Specifies the type of string comparison to use.

Can take the following values:

  • 0 = vbBinaryCompare - Performs a binary comparison
  • 1 = vbTextCompare - Performs a text comparison

Examples

Example 1

Filter: items containing "S":

<script type="text/vbscript">

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S")
for each x in b
document.write(x & "<br />")
next

</script>

Output of the above example:

Sunday
Saturday

Try it Yourself »

Example 2

Filter: items not containing "S" (include=False):

<script type="text/vbscript">

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",False)
for each x in b
document.write(x & "<br />")
next

</script>

Output of the above example:

Monday
Tuesday
Wednesday
Thursday
Friday

Try it Yourself »

Example 3

Filter: items containing "S", using text comparison (compare=1):

<script type="text/vbscript">

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True,1)
for each x in b
document.write(x & "<br />")
next

</script>

Output of the above example:

Sunday
Tuesday
Wednesday
Thursday
Saturday

Try it Yourself »

VBScript 参考手册Complete VBScript Reference Other Extensions