using System;
using System.Xml; // required so System.Xml library is referenced and used by HAP
using System.Text.RegularExpressions;
using HtmlAgilityPack;
public class Program
{
private static readonly Regex multiLF = new Regex(@"\n{3,}", RegexOptions.Compiled | RegexOptions.Singleline);
public static void Main()
var web = new HtmlWeb();
var doc = web.Load("http://stackoverflow.com/questions/30926684/truncating-html-content-at-the-end-of-text-blocks-block-elements");
var question = doc.DocumentNode.SelectSingleNode("//td[@class='postcell']//div[@class='post-text']");
string questionText = multiLF.Replace(question.InnerText.Trim(), "\n\n");
Console.WriteLine("\n-- FULL QUESTION TEXT ------------------------------------------\n");
Console.WriteLine(questionText);
string truncatedText = questionText.Substring(0, 1250);
truncatedText += "|MAX|";
truncatedText = truncatedText.Insert(1000, "|LIMIT|");
truncatedText = truncatedText.Insert(750, "|MIN|");
Console.WriteLine("\n-- FIRST 1250 CHARACTERS ---------------------------------------\n");
Console.WriteLine(truncatedText);
}
Operation failed. Please try again or report this to support.