I'm writing a simple script that checks wether a certain domain name (.com, .co.uk, etc...) is at the end of a string (e.g. Google.com) . I currently have it set up like this;
if (web_address.endsWith(".com") || web_address.endsWith(".co.uk") || web_address.endsWith(".gov") || web_address.endsWith(".de") ...........
{
//DO SOMETHING
}
else
{
//DO SOMETHING ELSE
}
The current condition compares 10 different domain names but there must be a better way to check this. I initially thought I could store these items in a list and run web_address.endsWith(list), however this doesn't check past the first item. Probably has to go inside a loop but I don't know the proper way to do this. (I've very bad at loops!).
Any idea how to make this more efficient? Thanks!
No responses yet.