I have an HTMLElementCollection that I'm going through using a For Each Loop to see if the InnerHTML contains certain words. If they do contain any of those keywords it gets saved into a file.

Everything works fine but I was wondering if there is a way to simplify. Here's a sample

For Each Helement As HtmlElement In elements

     If Helement.InnerHtml.Contains("keyword1") Or Helement.InnerHtml.Contains("keyword2") Or Helement.InnerHtml.Contains("keyword3") Or Helement.InnerHtml.Contains("keyword4") Or Helement.InnerHtml.Contains("keyword5") = True Then
         ' THE CODE TO COPY TO FILE
     End If

Next Helement
                  

Does anything exist that would work like:

If Helement.InnerHtml.Contains("keyword1", "keyword2", "keyword3", "keyword4", "keyword5")

The way I'm doing it now just seems wasteful, and I'm pretty OCD about it.

Here's another extension method that cleans up the logic a little with LINQ:

<!-- language: lang-vb -->
<Extension()>
Public Function MultiContains(str As String, ParamArray values() As String) As Boolean
    Return values.Any(Function(val) str.Contains(val))
End Function