FILTER                                                                   Function

FILTER (stringarray, value[, include[, compare]])

Description

FILTER returns an array of strings that is a subset of inputs that have met the specified filter criteria. The required parameter, stringarray, is a one-dimensional array of strings to be filtered. The required parameter, value, is a string expression to be searched for. The optional parameter, include, is a boolean value, when TRUE, the returned values are the strings that contain value, when FALSE, the returned values do not contain value. The default value of include is TRUE. The optional parameter, compare, is a numeric expression or constant that specifies the type of comparisons to perform, see below. The default value of compare is vbBinaryCompare.

Table 10: Comparison constants

Constant

Value

Description

vbBinaryCompare

0

Binary comparison, case sensitive (default)

vbTextCompare

1

Textual comparison, case insensitive

 

Example

REM FILTER Example

'FILTER finds matches in an array of strings

DIM Who, TheKs, NotEric

Who = ARRAY("Eric", "Kenny", "Kyle", "Stan")

TheKs = FILTER(Who, "k", TRUE,vbTextCompare)

NotEric = FILTER(Who, "Eric", FALSE, _

  vbBinaryCompare)

PrintArray "Who", Who

PrintArray "The K's", TheKs

PrintArray "Everyone but Eric", NotEric

SUB PrintArray(ArrName, Arr)

  DIM i

  PRINT ArrName

  FOR i = 0 TO UBOUND(Arr)

    PRINT "  " & Arr(i)

  NEXT

END SUB

Output

Who

  Eric

  Kenny

  Kyle

  Stan

The K's

  Kenny

  Kyle

Everyone but Eric

  Kenny

  Kyle

  Stan

Related Items

REPLACE