question

StevenYoung-5410 avatar image
0 Votes"
StevenYoung-5410 asked StevenYoung-5410 commented

Check in the string list

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)
     a.Add("abcd")
     a.Add("qwer")

     Dim x As String = "abcdef"
     For Each s As String In a
         If x.Contains(s) = True Then
             result = True
         End If
     Next
vs-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered StevenYoung-5410 commented

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)


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you so much

0 Votes 0 ·

Further questions.

Dim a As New List(Of String) From {"abcd", "qwer"}
Dim b As New List(Of String) From {"abcdef", "qweree","asdf"}

Want to return the IEnumberable or string list that strings in b contain any element in a.

0 Votes 0 ·