Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Filter Function

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.

Settings

The Compare argument can have the following values:

Constant Description
CompareMethod.Binary Performs a binary comparison
CompareMethod.Text Performs a textual comparison

Exceptions/Errors

Exception type Error number Condition
ArgumentException 5 Source is Nothing or is not a one-dimensional array.

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.

Example

This example demonstrates the use of the Filter function.

Dim myStrings(2) As String
MyStrings(0) = "This"
MyStrings(1) = "Is"
MyStrings(2) = "It"
' Returns ["This", "Is"].
Dim subStrings() As String = Filter(myStrings, "is", True, _
   CompareMethod.Text)
' Returns ["This"].
Dim subStrings() As String = Filter(myStrings, "is", True, _
   CompareMethod.Binary)
' Returns ["Is", "It"].
Dim subStrings() As String = Filter(myStrings, "is", False, _
   CompareMethod.Binary)

Requirements

Namespace: Microsoft.VisualBasic

Module: Strings

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

Replace Function | ArgumentException

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.