Muokkaa

Jaa


Strings.Filter Method

Definition

Returns a zero-based array containing a subset of a String array based on specified filter criteria.

Overloads

Filter(Object[], String, Boolean, CompareMethod)

Returns a zero-based array containing a subset of a String array based on specified filter criteria.

Filter(String[], String, Boolean, CompareMethod)

Returns a zero-based array containing a subset of a String array based on specified filter criteria.

Filter(Object[], String, Boolean, CompareMethod)

Source:
Strings.vb
Source:
Strings.vb
Source:
Strings.vb

Returns a zero-based array containing a subset of a String array based on specified filter criteria.

public static string[]? Filter (object?[] Source, string? Match, bool Include = true, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
public static string[] Filter (object[] Source, string Match, bool Include = true, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
static member Filter : obj[] * string * bool * Microsoft.VisualBasic.CompareMethod -> string[]
Public Function Filter (Source As Object(), Match As String, Optional Include As Boolean = true, Optional Compare As CompareMethod = Microsoft.VisualBasic.CompareMethod.Binary) As String()

Parameters

Source
Object[]

Required. One-dimensional array of strings to be searched.

Match
String

Required. String to search for.

Include
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
CompareMethod

Optional. Numeric value indicating the kind of string comparison to use. See "Settings" for values.

Returns

String[]

A zero-based array containing a subset of a String array based on specified filter criteria.

Exceptions

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

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)

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

See also

Applies to

Filter(String[], String, Boolean, CompareMethod)

Source:
Strings.vb
Source:
Strings.vb
Source:
Strings.vb

Returns a zero-based array containing a subset of a String array based on specified filter criteria.

public static string[]? Filter (string?[] Source, string? Match, bool Include = true, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
public static string[] Filter (string[] Source, string Match, bool Include = true, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
static member Filter : string[] * string * bool * Microsoft.VisualBasic.CompareMethod -> string[]
Public Function Filter (Source As String(), Match As String, Optional Include As Boolean = true, Optional Compare As CompareMethod = Microsoft.VisualBasic.CompareMethod.Binary) As String()

Parameters

Source
String[]

Required. One-dimensional array of strings to be searched.

Match
String

Required. String to search for.

Include
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
CompareMethod

Optional. Numeric value indicating the kind of string comparison to use. See "Settings" for values.

Returns

String[]

A zero-based array containing a subset of a String array based on specified filter criteria.

Exceptions

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

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)

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

See also

Applies to