How to check if url has a substring

I'm trying to do something that will allow all controls if the SubString in the WebBrowser matches the SubString in the textbox, and if it does, it will include all the controls, but I can't seem to get it to work. This is my current code.

        string str = "";
        int pos = str.IndexOf(".") + 1;
        int pos2 = str.LastIndexOf(".") - 4;
        string str2 = str.Substring(pos, pos2);
        if (webBrowser1.Url.AbsoluteUri.Substring(pos, pos2) == textBox1.Text.Substring(pos, pos2))
            foreach (Control c in Controls)
                c.Enabled = true;


Any help would be appreciated.


source to share

3 answers

The class Uri

is a wonderful thing.

Uri google = new Uri("");
if (webBrowser.Url.Host == google.Host){


Or even just:

if (webBrower.Url.Host.ToLower().Contains("google")) {




Just use string.contains





If you ONLY need to know that the substring exists inside the string, use String.Contains

as Justin Pihoni suggested.

If you need information where , in which it exists, use String.IndexOf()

. If the string doesn't exist at all, this method will return -1.



All Articles