Skip to content Skip to sidebar Skip to footer

Using Html Agility Pack To Select All Paragraphs That Start With A Certain Text Value

I am learning to use the Html Agility Pack. I have a series of paragraph elements that look like this (code split for clarity):

New Version</div><h2 id="solution_1">Solution 1:

</h2><div class="answer-desc"><p>You can get the first 5 paragraphs where the inner text starts with "Version" like this:</p><pre><code id="code_0" class="hljs language-javascript"><span class="hljs-keyword">var</span> nodesParagraph = nodeRevHist
    .<span class="hljs-title class_">Elements</span>(<span class="hljs-string">"p"</span>)
    .<span class="hljs-title class_">Where</span>(<span class="hljs-function"><span class="hljs-params">p</span> =></span> p.<span class="hljs-property">InnerText</span>.<span class="hljs-title class_">Trim</span>().<span class="hljs-title class_">StartsWith</span>(<span class="hljs-string">"Version"</span>))
    .<span class="hljs-title class_">Take</span>(<span class="hljs-number">5</span>);
</code><button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,Copy

Working demo here: https://dotnetfiddle.net/uvwcUN

Post a Comment for "Using Html Agility Pack To Select All Paragraphs That Start With A Certain Text Value"