title: Read first 3 paragraphs of a long string. [C#, HTML AgilityPack]
body: <p>I would like to read from a long string and just output the first 3 paragraphs of the string. How do I achieve this? I wanted to use this code to show (n) number of words but I have since changed to paragraphs. </p>
  
  <pre><code>public string MySummary(string html, int max)
  {
      string summaryHtml = string.Empty;
  
      // load our html document
      HtmlDocument htmlDoc = new HtmlDocument();
      htmlDoc.LoadHtml(html);
  
      int wordCount = 0;
  
  
  
  
      foreach (var element in htmlDoc.DocumentNode.ChildNodes)
      {
          // inner text will strip out all html, and give us plain text
          string elementText = element.InnerText;
  
          // we split by space to get all the words in this element
          string[] elementWords = elementText.Split(new char[] { ' ' });
  
          // and if we haven't used too many words ...
  
          if (wordCount &lt;= max)
          {
              // add the *outer* HTML (which will have proper 
              // html formatting for this fragment) to the summary
              summaryHtml += element.OuterHtml;
              wordCount += elementWords.Count() + 1;
  
          }
          else
          {
              break;
          }
      }
  
      return summaryHtml ;
  }
  </code></pre>