Filter: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Brendon (talk | contribs)
Created page with "FILTER (''stringarray'', ''value''[, ''include''[, ''compare'']]) '''Description''' FILTER returns an array of strings that is a subset of inputs that have met the specified..."
 
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
FILTER (''stringarray'', ''value''[, ''include''[, ''compare'']])
''This function is for BASIC compatibility. It is not available in pure JavaScript projects.''  


'''Description'''
Filter (''stringarray'', ''value''[, ''include''[, ''compare'']])


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.
== 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'''
'''Table 10: Comparison constants'''
Line 16: Line 18:
|}
|}


'''Example'''
== Example (Basic) ==


<pre>
<pre>
REM FILTER Example
Rem Filter Example
'FILTER finds matches in an array of strings
'Filter finds matches in an array of strings
DIM Who, TheKs, NotEric
Dim Who, TheKs, NotEric
Who = ARRAY("Eric", "Kenny", "Kyle", "Stan")
Who = Array("Eric", "Kenny", "Kyle", "Stan")
TheKs = FILTER(Who, "k", TRUE,vbTextCompare)
TheKs = Filter(Who, "k", TRUE,vbTextCompare)
NotEric = FILTER(Who, "Eric", FALSE, _
NotEric = Filter(Who, "Eric", FALSE, _
   vbBinaryCompare)
   vbBinaryCompare)
PrintArray "Who", Who
PrintArray "Who", Who
PrintArray "The K's", TheKs
PrintArray "The K's", TheKs
PrintArray "Everyone but Eric", NotEric
PrintArray "Everyone but Eric", NotEric
SUB PrintArray(ArrName, Arr)
Sub PrintArray(ArrName, Arr)
   DIM i
   Dim i
   PRINT ArrName
   Print ArrName
   FOR i = 0 TO UBOUND(Arr)
   For i = 0 TO UBound(Arr)
     PRINT "  " & Arr(i)
     Print "  " & Arr(i)
   NEXT
   Next
END SUB
End Sub
</pre>
</pre>


'''Output'''
== Output ==


<pre>
<pre>
Line 55: Line 57:
</pre>
</pre>


'''Related items'''
== Related items ==
 
[[replace|Replace]]
 
[[Category:Language Reference]]
 
[[Category:Strings]]


[[replace|REPLACE]]
[[Category:BASIC Functions]]

Latest revision as of 15:24, 25 March 2019

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