Filter

From NSB App Studio
Jump to navigation Jump to search

This function is for BASIC compatibility. It is not available in pure JavaScript projects.

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 (Basic)

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