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()
The Compare argument can have the following values:
Constant | Description |
---|---|
CompareMethod.Binary | Performs a binary comparison |
CompareMethod.Text | Performs a textual comparison |
Exception type | Error number | Condition |
---|---|---|
5 | 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.
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)
Replace Function |