O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Filter Function

Syntax

Filter(SourceArray, FilterString[, Switch[, Compare]])
SourceArray

Use: Required

Data Type: String or numeric

An array containing values to be filtered.

FilterString

Use: Required

Data Type: String or numeric

The string of characters to find in the source array.

Switch

Use: Optional

Data Type: Boolean

A Boolean (True or False) value. If True, the default value, Filter includes all matching values in result; if False, Filter excludes all matching values (or, to put it another way, includes all nonmatching values).

Compare

Use: Optional

Data Type: Long

An optional constant (possible values are 0, vbBinaryCompare; 1, vbTextCompare) that indicates the type of string comparison to use. The default value is 0, vbBinaryCompare.

Return Value

A String array of the elements filtered from SourceArray.

Description

Produces an array of matching values from an array of source values that either match or don’t match a given filter string. In other words, individual elements are copied from a source array to a target array if they either match or don’t match a filter string.

Rules at a Glance

  • The default Switch value is True.

  • The default Compare value is 0, vbBinaryCompare.

  • vbBinaryCompare is case-sensitive; that is, Filter matches both character and case. In contrast, vbTextCompare is case-insensitive, matching only character regardless of case.

Programming Tips and Gotchas

  • SourceArray elements that are Empty or that contain zero-length strings (“”) are ignored by the Filter function.

  • The array ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required