Trigger breakpoint when string is not a Google-owned domain Basically, I want the code to break when strLink doesn't contain any domains in the googleDomains link.

The code seems to be very awkward. I wonder if there is a way to make this more elegant.

Dim googleDomains = {"google.com", "blogger.com", "youtube.com"}
Dim pass = False
For Each domaingoogle In googleDomains
    If strLink.Contains(domaingoogle) Then
        pass = True
    End If
Next
If Not pass Then
    Dim hello2 = 1 'set breakpoint here.
End If
One thing you could look at is Regex. If you're willing to assume that strLink is in fact a valid URL you could try something like

Dim googleDomains = {"google.com", "blogger.com", "youtube.com"}
Dim regexp = "^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+\.com)"
Dim match = Regex.Match(strLink, regexp)
If match.Length &lt;&gt; 0 Then
    Dim domain As String = match.Groups(1).Value
    If Not googleDomains.Contains(domain) Then
        Dim hello2 = 1 'set breakpoint here.
    End If
End If


If you wanted to expand to include ".org" or ".net" you could do something like this:

Dim regexp = "^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+\.(com|org|net|gov))"


Modified Example Regex Demo

In general, I'd say Regex is a very useful tool to have in your arsenal and would be good to learn. Comes in handy when you need to scan large code files or restructure something in a lot of places (as Regex can do replacements as well)

In this example the main benefit is that you can actually extract out the domain from a well-formed URL rather than just see if "google.com" is anywhere in the string



If you want the actual check to truly be String.Contains You could do something with LINQ

Dim domain = googleDomains.FirstOrDefault(Function(d) strLink.Contains(d))
If domain = Nothing Then
    Dim hello2 = 1 'set breakpoint here.
End If


A little bit less verbose, but it doesn't necessarily mean the string is a valid URL to google.com