How to determine whether string array contains elements that start with a given letter in VB.NET

1 Answer

0 votes
Module Module1

    Sub Main()

        Dim s() As String = {"PHP", "C", "C++", "C#", "Java", "JavaScript", "VB.NET"}

        Console.WriteLine("One Or more strings begin with 'C': {0}",
                           Array.Exists(s, Function(element)
                                               Return element.StartsWith("C")
                                           End Function))
        Console.WriteLine("One Or more strings begin with 'J': {0}",
                         Array.Exists(s, Function(element)
                                             Return element.StartsWith("J")
                                         End Function))
        Console.WriteLine("One Or more strings begin with 'W': {0}",
                           Array.Exists(s, Function(element)
                                               Return element.StartsWith("W")
                                           End Function))
    End Sub

End Module

' run:
' 
' One Or more strings begin with 'C': True
' One Or more strings begin with 'J': True
' One Or more strings begin with 'W': False

 



answered Apr 15, 2016 by avibootz
...