Strings.Filter 方法

定义

返回一个从零开始的数组,该数组包含基于指定筛选条件的 String 数组的子集。Returns a zero-based array containing a subset of a String array based on specified filter criteria.

重载

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

返回一个从零开始的数组,该数组包含基于指定筛选条件的 String 数组的子集。Returns a zero-based array containing a subset of a String array based on specified filter criteria.

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

返回一个从零开始的数组,该数组包含基于指定筛选条件的 String 数组的子集。Returns a zero-based array containing a subset of a String array based on specified filter criteria.

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

返回一个从零开始的数组,该数组包含基于指定筛选条件的 String 数组的子集。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);
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()

参数

Source
Object[]

必需。Required. 要搜索的一维字符串数组。One-dimensional array of strings to be searched.

Match
String

必需。Required. 要搜索的字符串。String to search for.

Include
Boolean

可选。Optional. Boolean 值,指示是返回包含还是排除 Match 的子字符串。Boolean value indicating whether to return substrings that include or exclude Match. 如果 IncludeTrue,则 Filter 函数返回将 Match 作为子字符串包含在其中的数组的子集。If Include is True, the Filter function returns the subset of the array that contains Match as a substring. 如果 IncludeFalse,则 Filter 函数返回不将 Match 作为子字符串包含在其中的数组的子集。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.

返回

String[]

一个从零开始的数组,该数组包含基于指定筛选条件的 String 数组的子集。A zero-based array containing a subset of a String array based on specified filter criteria.

异常

SourceNothing 或不是一维数组。Source is Nothing or is not a one-dimensional array.

示例

此示例演示如何使用 Filter 函数。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)

注解

如果 Source 中找不到 Match 的匹配项,则 @no__t 2 函数返回一个空数组。If no matches of Match are found within Source, the Filter function returns an empty array. 如果 @no__t 设置为 @no__t 或不是一维数组,则会发生错误。An error occurs if Source is set to Nothing or is not a one-dimensional array.

@No__t-0 函数返回的数组包含的元素数足以包含匹配项的数目。The array returned by the Filter function contains only enough elements to contain the number of matched items.

@No__t 参数可以具有下列值。The Compare argument can have the following values.

返回的常量Constant 说明Description
返回的常量Constant 说明Description
CompareMethod.Binary 执行二进制比较Performs a binary comparison
CompareMethod.Text 执行文本比较Performs a textual comparison

另请参阅

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

返回一个从零开始的数组,该数组包含基于指定筛选条件的 String 数组的子集。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);
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()

参数

Source
String[]

必需。Required. 要搜索的一维字符串数组。One-dimensional array of strings to be searched.

Match
String

必需。Required. 要搜索的字符串。String to search for.

Include
Boolean

可选。Optional. Boolean 值,指示是返回包含还是排除 Match 的子字符串。Boolean value indicating whether to return substrings that include or exclude Match. 如果 IncludeTrue,则 Filter 函数返回将 Match 作为子字符串包含在其中的数组的子集。If Include is True, the Filter function returns the subset of the array that contains Match as a substring. 如果 IncludeFalse,则 Filter 函数返回不将 Match 作为子字符串包含在其中的数组的子集。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.

返回

String[]

一个从零开始的数组,该数组包含基于指定筛选条件的 String 数组的子集。A zero-based array containing a subset of a String array based on specified filter criteria.

异常

SourceNothing 或不是一维数组。Source is Nothing or is not a one-dimensional array.

示例

此示例演示如何使用 Filter 函数。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)

注解

如果 Source 中找不到 Match 的匹配项,则 @no__t 2 函数返回一个空数组。If no matches of Match are found within Source, the Filter function returns an empty array. 如果 @no__t 设置为 @no__t 或不是一维数组,则会发生错误。An error occurs if Source is set to Nothing or is not a one-dimensional array.

@No__t-0 函数返回的数组包含的元素数足以包含匹配项的数目。The array returned by the Filter function contains only enough elements to contain the number of matched items.

@No__t 参数可以具有下列值。The Compare argument can have the following values.

返回的常量Constant 说明Description
CompareMethod.Binary 执行二进制比较Performs a binary comparison
CompareMethod.Text 执行文本比较Performs a textual comparison

另请参阅

适用于