Reputation: 671
I have two code for getting no of characters inside templates first one is
string html = this.GetHTMLContent(url);
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
StringBuilder sb = new StringBuilder();
foreach (HtmlTextNode node in doc.DocumentNode.SelectNodes("//text()"))
{
sb.AppendLine(node.InnerText);
}
string final = sb.ToString();
int lenght = final.Length;
And second one is
var length = doc.DocumentNode.SelectNodes("//text()")
.Where(x => x.NodeType == HtmlNodeType.Text)
.Select(x => x.InnerText.Length)
.Sum();
When I run both code return me different result.
Upvotes: 1
Views: 84
Reputation: 671
Finally I identified the problem. the problem was inside loop I used appendLine() method instead of append() method. so it appended new line each time of looping. So that some white spaces it also recognized as character.
Upvotes: 1