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

Strings.Filter Method (String[], String, Boolean, CompareMethod)

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)
public static string[] Filter(
	string[] Source,
	string Match,
	bool Include,
	CompareMethod Compare
)

Parameters

Source
Type: 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: System.String[]
Returns a zero-based array containing a subset of a String array based on specified filter criteria.
ExceptionCondition
ArgumentException

Source is Nothing or is not a one-dimensional array.

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

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)

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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