Answer the question
In order to leave comments, you need to log in
Parsing html with c# standard tools?
There is an html code with an element:
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Hello word</div>
Answer the question
In order to leave comments, you need to log in
If you have the correct html with closing tags, then you can try using XDocument or XElement
Conditionally, somewhere like this:
var xEl = XElement.Parse("<div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal\">Hello word</div>");
Console.WriteLine((string)xEl);
var xDoc = XDocument.Parse("<div><div class='c1'>c1</div><div class='c2'>c2</div><div class='c3'>c3</div></div>");
string xPath = "//div[@class='c1']";
foreach (var xElement in xDoc.XPathSelectElements(xPath))
{
Console.WriteLine((string)xElement);
}
for poorly defined html, there is
HTMLAgilityPack
CsQuery
Fizzler (I myself once tried this) and there are a lot of alternatives https://stackoverflow.com/questions/1065031/is-the... there is nuget
If you really need to parse HTML using regular expressions, you can do this
string html = "<div style=\"font - family: 'Courier New', Courier, monospace; font - weight: normal; \">Hello word</div>";
Regex regex = new Regex("<div style=\"font - family: 'Courier New', Courier, monospace; font - weight: normal; \">(.*)<\\/div>");
string text = regex.Match(html).Groups[1].Value;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question