Match exact string using string.Contains() method in c#

c# html-agility-pack

Question

I have an html content. I'm parsing the content using HtmlAgilityPack. I Need to replace attribute
'align = "middle"' with 'align = "center"', I'm using function

if(htmlDoc.DocumentNode.OuterHttml.Contains("align = "middle""))
htmlDoc.DocumentNode.OuterHttml.Replace("align = "middle","align = "center"")

But if condition is returning true even for **valign = "middle"** !

What is that i need to put in if condition other than Contains()?

1
0
9/4/2013 12:16:55 PM

Accepted Answer

yes I'm trying to find match inside an html content.

Then use HtmlAgilityPack. Your code would be something like.

var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(HtmlString);

var tds = doc.DocumentNode.SelectNodes("//td[@align='middle']");

or something like this using LINQ

var tds = doc.DocumentNode.Descendants("td")
                .Where(td => td.Attributes["align"].Value == "middle")
                .ToList();
4
8/30/2013 10:39:20 AM

Popular Answer

if your string is like "blablabla align = 'align = \"middle\" blablabla" then you can do:

Contains(" align = \"middle\" ") // spaces before and after

But how others says it's hard to understand what you want exactly.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow