-1

I am fetching Anchor Tag data from a URL using HTMLAGILITYPACK but with some kind of Comparison. I have some String type Variables with some value All I want is to Compare with Fetched Anchor Tag and Print it.

NOTE: There are three words in a String Variable I want to print those who matches its first value or any of them.

Here is My Code

foreach (var aTag in atags)
{
    string val1 = "Something is there";
    string val2 = "There is Nothing";
    if (val1 == aTag.InnerHtml || val2 == aTag.InnerHtml)
    {
        OutputLabel.Text += counter + ". " + aTag.InnerHtml + "<br /><br />";
    }
    counter++; 
}

I tried to Use Similary Posted Questions but that doesn't seems to work for me.

Mohiyo Deen
  • 125
  • 3
  • 17
  • 1
    could you explain a bit more what you're trying to achieve exactly? – Shtut Mar 04 '17 at 20:18
  • split the strings and `stringToCheck.Contains(x)` – Mark Schultheiss Mar 04 '17 at 20:20
  • Its simple, Just getting Anchor Tag Text using HTMLAGILITYPACK, but only those that fulfills the Condition. – Mohiyo Deen Mar 04 '17 at 20:21
  • 1
    Possible duplicate of [Using C# to check if string contains a string in string array](http://stackoverflow.com/questions/2912476/using-c-sharp-to-check-if-string-contains-a-string-in-string-array) – Mark Schultheiss Mar 04 '17 at 20:23
  • @MarkSchultheiss that doesn't seems to work, That solution will only return if two strings are Exact Match that is not my need. I just need if string x = "Left is Right" and strin tocompare = "Left" it should return matching because work "Left" is in 'X' – Mohiyo Deen Mar 04 '17 at 20:38
  • linq `val1 .Split() .Intersect(aTag.InnerHtml.Split()) .Any();` might need to modify the tag split for the html i.e not just white space separater – Mark Schultheiss Mar 04 '17 at 20:50

1 Answers1

1

Try do that:

// first we breake the words to see if anyone match on the innerhtml
var itens = val1.Split(',');
// after that we select just the itens matched on content
var itensMatchedOnContent = itens.Where(w => aTag.InnerHtml.Contains(w)).ToArray();

I hope it can help you.