Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to use Array.TrueForAll() method to determine whether all array elements match a condition in VB.NET

3 Answers

0 votes
Module Module1

    Sub Main()

        Dim arr As String() = {"hhh10", "ccc100", "bbb1000", "ggg10000",
                               "eee100000", "aaa100000", "ddd333"}

        If Array.TrueForAll(arr, AddressOf EndsWithInteger) Then
            Console.WriteLine("All elements end with integer")
        Else
            Console.WriteLine("Not all elements end with an integer")
        End If

    End Sub

    Private Function EndsWithInteger(value As String) As Boolean
        Dim s As Integer
        Return Int32.TryParse(value.Substring(value.Length - 1), s)
    End Function

End Module

' run:
' 
' All elements end with integer

 



answered May 2, 2016 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim arr As String() = {"hhh", "ccc100", "bbb1000", "ggg10000", "eee100000"}

        If Array.TrueForAll(arr, AddressOf EndsWithInteger) Then
            Console.WriteLine("All elements end with integer")
        Else
            Console.WriteLine("Not all elements end with an integer")
        End If

    End Sub

    Private Function EndsWithInteger(value As String) As Boolean
        Dim s As Integer
        Return Int32.TryParse(value.Substring(value.Length - 1), s)
    End Function

End Module

' run:
' 
' Not all elements end with an integer

 



answered May 2, 2016 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim arr As String() = {"hhh12345", "ccc100", "bbb1000", "ggg10000"}

        If Array.TrueForAll(arr, Function(value)
                                     Dim s As Integer
                                     Return Int32.TryParse(value.Substring(value.Length - 1), s)
                                 End Function) Then
            Console.WriteLine("All elements end with integer")
        Else
            Console.WriteLine("Not all elements end with an integer")
        End If

    End Sub

End Module

' run:
' 
' All elements end with integer

 



answered May 2, 2016 by avibootz
...