Check in the string list

Steven Young 261 Reputation points

I have the code below, do I have to use the loop? Is there a better way? thank you.

Dim result As Boolean

    Dim a As New List(Of String)

    Dim x As String = "abcdef"
    For Each s As String In a
        If x.Contains(s) = True Then
            result = True
        End If
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
3,157 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 94,511 Reputation points

    Try this alternative:

    Dim a As New List(Of String) From {"abcd", "qwer"}
    Dim x As String = "abcdef"
    Dim result As Boolean = a.Any(AddressOf x.Contains)

0 additional answers

Sort by: Most helpful