To clarify, it
appears you are checking if the
text of the link matches
url
, not if the
target of the link matches?
So a link like:
<a href="http://google.com/">http://www.adireo.com/</a>
should be a
match?
I don't see the reason that you need to compare char-by-char.
StringComparison.Ordinal
will do the most-exact comparison.
If you just want a true/false that some link matches
url
try something like this:
private void tags_get()
{
const string url="http://www.adireo.com/";
var links = webBrowserCtl.Document.Links;
bool found = links.Any(link => string.Equals(link.InnerText, url, System.StringComparison.Ordinal));
MessageBox.Show(found ? "found" : "Not Found");
}
Assuming you want to do something with the links after determining that
url
is/isn't present, you could get a Dictionary of the links keyed by the
text or
target:
private void tags_get()
{
Dictionary<string, HtmlElement> linkMap = new Dictionary<string, HtmlElement>(StringComparer.Ordinal);
const string url="http://www.adireo.com/";
foreach (HtmlElement link in webBrowserCtl.Document.Links)
{
string key = link.InnerText; if (linkMap.ContainsKey(key))
{
}
linkMap.Add(key, link);
}
if (linkMap.ContainsKey(url))
{
MessageBox.Show("found");
}
else
{
MessageBox.Show("Not Found");
}
}