Filter Function (Visual Basic)
Returns a zero-based array containing a subset of a String array based on specified filter criteria.
Function Filter(
ByVal Source() As { Object | String },
ByVal Match As String,
Optional ByVal Include As Boolean = True,
Optional ByVal Compare As CompareMethod = CompareMethod.Binary
) As String()
Parameters
- Source
-
Required. One-dimensional array of strings to be searched.
- Match
-
Required. String to search for.
- Include
-
Optional. Boolean value indicating whether to return substrings that include or exclude Match. If Include is True, the Filter function returns the subset of the array that contains Match as a substring. If Include is False, the Filter function returns the subset of the array that does not contain Match as a substring.
- Compare
-
Optional. Numeric value indicating the kind of string comparison to use. See "Settings" for values.
| Exception type | Error number | Condition |
|---|---|---|
| Source is Nothing or is not a one-dimensional array. |
See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.
This example demonstrates the use of the Filter function.
Dim TestStrings(2) As String TestStrings(0) = "This" TestStrings(1) = "Is" TestStrings(2) = "It" Dim subStrings() As String ' Returns ["This", "Is"]. subStrings = Filter(TestStrings, "is", True, CompareMethod.Text) ' Returns ["This"]. subStrings = Filter(TestStrings, "is", True, CompareMethod.Binary) ' Returns ["Is", "It"]. subStrings = Filter(TestStrings, "is", False, CompareMethod.Binary)
Namespace: Microsoft.VisualBasic
Module: Strings
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)