Strings.Filter Method (array<String[], String, Boolean, CompareMethod)
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Returns a zero-based array containing a subset of a String array based on specified filter criteria.
Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
Syntax
'Declaration
Public Shared Function Filter ( _
    Source As String(), _
    Match As String, _
    Include As Boolean, _
    Compare As CompareMethod _
) As String()
public static string[] Filter(
    string[] Source,
    string Match,
    bool Include,
    CompareMethod Compare
)
Parameters
- Source
 Type: array<System.String[]
 Required. One-dimensional array of strings to be searched.
- Match
 Type: System.String
 Required. String to search for.
- Include
 Type: System.Boolean
 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
 Type: Microsoft.VisualBasic.CompareMethod
 Optional. Numeric value indicating the kind of string comparison to use. See "Settings" for values.
Return Value
Type: array<System.String[]
Returns a zero-based array containing a subset of a String array based on specified filter criteria.
Remarks
If no matches of Match are found within Source, the Filter function returns an empty array. An error occurs if Source is set to Nothing or is not a one-dimensional array.
The array returned by the Filter function contains only enough elements to contain the number of matched items.
The Compare argument can have the following values.
| Constant | Description | 
|---|---|
| CompareMethod.Binary | Performs a binary comparison | 
| CompareMethod.Text | Performs a textual comparison | 
Examples
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)
Version Information
Silverlight
Supported in: 5, 4, 3
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
See Also