title: Extracting text fragment from a HTML body (in .NET)
body: <p>I have an HTML content which is entered by user via a richtext editor so it can be almost anything (less those not supposed to be outside the body tag, no worries about "head" or doctype etc).
  An example of this content:</p>
  
  <pre><code>&lt;h1&gt;Header 1&lt;/h1&gt;
  &lt;p&gt;Some text here&lt;/p&gt;&lt;p&gt;Some more text here&lt;/p&gt;
  &lt;div align=right&gt;&lt;a href="x"&gt;A link here&lt;/a&gt;&lt;/div&gt;&lt;hr /&gt;
  &lt;h1&gt;Header 2&lt;/h1&gt;
  &lt;p&gt;Some text here&lt;/p&gt;&lt;p&gt;Some more text here&lt;/p&gt;
  &lt;div align=right&gt;&lt;a href="x"&gt;A link here&lt;/a&gt;&lt;/div&gt;&lt;hr /&gt;
  </code></pre>
  
  <p>The trick is, I need to extract first 100 characters of the text only (HTML tags stripped). I also need to retain the line breaks and not break any word.</p>
  
  <p>So the output for the above will be something like:</p>
  
  <blockquote>
  <pre><code>Header 1
  Some text here
  
  Some more text here
  
  A link here
  
  Header 2
  Some text here
  
  Some
  </code></pre>
  </blockquote>
  
  <p>It has 98 characters and line breaks are retained. What I can achieve so far is to strip the all HTML tags using Regex:</p>
  
  <pre><code>Regex.Replace(htmlStr, "&lt;[^&gt;]*&gt;", "")
  </code></pre>
  
  <p>Then trim the length using Regex as well with:</p>
  
  <pre><code>Regex.Match(textStr, @"^.{1,100}\b").Value
  </code></pre>
  
  <p>My problem is, how to retaining the line break?. I get an output like:</p>
  
  <blockquote>
  <pre><code>Header 1
  Some text hereSome more text here
  A link here
  Header 2
  Some text hereSome more text
  </code></pre>
  </blockquote>
  
  <p>Notice the joining sentences? Perhaps someone can show me some other ways of solving this problem. Thanks!</p>
  
  <p><strong>Additional Info</strong>: My purpose is to generate plain text synopsis from a bunch of HTML content. Guess this will help clarify the this problem.</p>