C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Lambda: In this example, we use lambda expressions that handle String elements. We name each String element "x".
LambdaStartsWith: We use the StartsWith Function to test prefixes. We use the Length property to access character counts.
StartsWith, EndsWithString LengthFindAll: We also apply the FindAll Function. This is similar to Find, but it returns an array of all the elements found.
Info: Find returns only one element. If no matches are found, Nothing is returned.
NothingVB.NET program that uses Find, FindAll
Module Module1
Sub Main()
' Input array.
Dim arr() As String = {"cat", "dog", "carrot", "bird"}
' Find element starting with "car".
Dim value1 As String = Array.Find(arr, Function(x) (x.StartsWith("car")))
Console.WriteLine(value1)
' Find element of length 3.
Dim value2 As String = Array.Find(arr, Function(x) (x.Length = 3))
Console.WriteLine(value2)
' Find all elements of length 4 or less.
Dim arr2() As String = Array.FindAll(arr, Function(x) (x.Length <= 4))
Console.WriteLine(String.Join(",", arr2))
End Sub
End Module
Output
carrot
cat
cat,dog,bird