Strings.Filter Metoda
Definice
Vrací pole s nulovým základem obsahující podmnožinu String pole na základě zadaných kritérií filtru.Returns a zero-based array containing a subset of a String array based on specified filter criteria.
Přetížení
| Filter(Object[], String, Boolean, CompareMethod) |
Vrací pole s nulovým základem obsahující podmnožinu |
| Filter(String[], String, Boolean, CompareMethod) |
Vrací pole s nulovým základem obsahující podmnožinu |
Filter(Object[], String, Boolean, CompareMethod)
Vrací pole s nulovým základem obsahující podmnožinu String pole na základě zadaných kritérií filtru.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()
Parametry
- Source
- Object[]
Povinná hodnota.Required. Jednorozměrné pole řetězců, které se má prohledat.One-dimensional array of strings to be searched.
- Match
- String
Povinná hodnota.Required. Řetězec, který chcete vyhledat.String to search for.
- Include
- Boolean
Nepovinný parametr.Optional. Boolean hodnota, která označuje, zda se mají vracet podřetězce, které jsou zahrnuty nebo vyloučeny Match .Boolean value indicating whether to return substrings that include or exclude Match. Pokud Include je True , Filter funkce vrátí podmnožinu pole, který obsahuje Match jako podřetězec.If Include is True, the Filter function returns the subset of the array that contains Match as a substring. Pokud Include je False , Filter funkce vrátí podmnožinu pole, která neobsahuje Match jako podřetězec.If Include is False, the Filter function returns the subset of the array that does not contain Match as a substring.
- Compare
- CompareMethod
Nepovinný parametr.Optional. Číselná hodnota označující druh porovnání řetězce, který se má použít.Numeric value indicating the kind of string comparison to use. Hodnoty naleznete v části „Nastavení“.See "Settings" for values.
Návraty
- String[]
Pole s nulovým základem obsahující podmnožinu String pole na základě zadaných kritérií filtru.A zero-based array containing a subset of a String array based on specified filter criteria.
Výjimky
Source je Nothing nebo není jednorozměrné pole.Source is Nothing or is not a one-dimensional array.
Příklady
Tento příklad ukazuje použití Filter funkce.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)
Poznámky
Pokud Match v aplikaci nenajde žádné shody Source , Filter funkce vrátí prázdné pole.If no matches of Match are found within Source, the Filter function returns an empty array. Pokud Source je nastaven na nebo není jednorozměrné Nothing pole, dojde k chybě.An error occurs if Source is set to Nothing or is not a one-dimensional array.
Pole vrácené Filter funkcí obsahuje pouze tolik prvků, aby obsahovalo počet odpovídajících položek.The array returned by the Filter function contains only enough elements to contain the number of matched items.
CompareArgument může obsahovat následující hodnoty.The Compare argument can have the following values.
| KonstantaConstant | DescriptionDescription |
|---|---|
CompareMethod.Binary |
Provádí binární porovnání.Performs a binary comparison |
CompareMethod.Text |
Provádí textové porovnání.Performs a textual comparison |
Viz také
- Replace(String, String, String, Int32, Int32, CompareMethod)
- ArgumentException
- Souhrn manipulace s řetězciString Manipulation Summary
Platí pro
Filter(String[], String, Boolean, CompareMethod)
Vrací pole s nulovým základem obsahující podmnožinu String pole na základě zadaných kritérií filtru.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()
Parametry
- Source
- String[]
Povinná hodnota.Required. Jednorozměrné pole řetězců, které se má prohledat.One-dimensional array of strings to be searched.
- Match
- String
Povinná hodnota.Required. Řetězec, který chcete vyhledat.String to search for.
- Include
- Boolean
Nepovinný parametr.Optional. Boolean hodnota, která označuje, zda se mají vracet podřetězce, které jsou zahrnuty nebo vyloučeny Match .Boolean value indicating whether to return substrings that include or exclude Match. Pokud Include je True , Filter funkce vrátí podmnožinu pole, který obsahuje Match jako podřetězec.If Include is True, the Filter function returns the subset of the array that contains Match as a substring. Pokud Include je False , Filter funkce vrátí podmnožinu pole, která neobsahuje Match jako podřetězec.If Include is False, the Filter function returns the subset of the array that does not contain Match as a substring.
- Compare
- CompareMethod
Nepovinný parametr.Optional. Číselná hodnota označující druh porovnání řetězce, který se má použít.Numeric value indicating the kind of string comparison to use. Hodnoty naleznete v části „Nastavení“.See "Settings" for values.
Návraty
- String[]
Pole s nulovým základem obsahující podmnožinu String pole na základě zadaných kritérií filtru.A zero-based array containing a subset of a String array based on specified filter criteria.
Výjimky
Source je Nothing nebo není jednorozměrné pole.Source is Nothing or is not a one-dimensional array.
Příklady
Tento příklad ukazuje použití Filter funkce.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)
Poznámky
Pokud Match v aplikaci nenajde žádné shody Source , Filter funkce vrátí prázdné pole.If no matches of Match are found within Source, the Filter function returns an empty array. Pokud Source je nastaven na nebo není jednorozměrné Nothing pole, dojde k chybě.An error occurs if Source is set to Nothing or is not a one-dimensional array.
Pole vrácené Filter funkcí obsahuje pouze tolik prvků, aby obsahovalo počet odpovídajících položek.The array returned by the Filter function contains only enough elements to contain the number of matched items.
CompareArgument může obsahovat následující hodnoty.The Compare argument can have the following values.
| KonstantaConstant | DescriptionDescription |
|---|---|
CompareMethod.Binary |
Provádí binární porovnání.Performs a binary comparison |
CompareMethod.Text |
Provádí textové porovnání.Performs a textual comparison |
Viz také
- Replace(String, String, String, Int32, Int32, CompareMethod)
- ArgumentException
- Souhrn manipulace s řetězciString Manipulation Summary