I am trying to make something that will enable all controls if a SubString in a WebBrowser matches a SubString in a TextBox and if it does it will enable all controls, but I can't seem to get it to work.
This is my current code:
string str = "www.google.com";
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 and all help will be appreciated.
Use indexOf() to Check if URL Contains a String When a URL contains a string, you can check for the string's existence using the indexOf method from String. prototype. indexOf() . Therefore, the argument of indexOf should be your search string.
To check if a url has query parameters, call the includes() method on the string, passing it a question mark as a parameter, e.g. str. includes('? ') . If the url contains query parameters, the includes method will return true , otherwise false is returned.
How do you check if the URL contains a given string in jQuery? Whether you are using jQuery or JavaScript for your frontend, you can simply use the indexOf() method with the href property using windows. The method indexOf() returns the position (a number) of the first occurrence of a given string.
The indexOf() method returns the position of the first occurrence of a value in a string. The indexOf() method returns -1 if the value is not found.
The Uri
class is a wonderful thing.
Uri google = new Uri("http://www.google.com/");
if (webBrowser.Url.Host == google.Host){
}
Or even simply:
if (webBrower.Url.Host.ToLower().Contains("google")) {
}
Just use string.contains
if(textBox1.Text.ToLower().Contains(str.ToLower()))
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With