If I have a string in html format like this:
<p style="text-align:center"> </p>
<p style="text-align:center"> </p>
<p style="text-align:center"><strong>To The ‎<span>Embassy of The United Kingdom</span>‏</strong></p>
<p>The ORG- certifies that ‎<strong><span>Mrs.</span></strong>‏‎<strong> </strong>‏‎<strong><span>Matilda Johan</span></strong>‏,</p>
<p>has been‎‏‎‏ working since <strong><span>01/10/2003</span></strong>‏ until present.</p>
<p>‎<span>Presently, she is working as</span>‏‎‏‎ a / an ‎<strong><span>JOB TITLE NOT DEFINED</span></strong>‏ at <strong><span>Dean of the Faculty of Engineering and Technology Office - College of Engineering and Technology - S</span></strong>‏-‎‏‎‎<strong><span>College of Engineering and Technology </span></strong>‏.</p>
<p><strong>This certificate was issued upon </strong>‎<strong><span>her request</span></strong>‏ <strong>and without any commitment on behalf of the ORG.</strong></p>
<div>
<div id="dv_sign_en" style="float:left;clear:both;font-style: italic;">...</div>
<div></div>
</div>
How to get the string only before the parent div for the div with id start with dv_sign_
so the result will be:
<p style="text-align:center"> </p>
<p style="text-align:center"> </p>
<p style="text-align:center"><strong>To The ‎<span>Embassy of The United Kingdom</span>‏</strong></p>
<p>The ORG- certifies that ‎<strong><span>Mrs.</span></strong>‏‎<strong> </strong>‏‎<strong><span>Matilda Johan</span></strong>‏,</p>
<p>has been‎‏‎‏ working since <strong><span>01/10/2003</span></strong>‏ until present.</p>
<p>‎<span>Presently, she is working as</span>‏‎‏‎ a / an ‎<strong><span>JOB TITLE NOT DEFINED</span></strong>‏ at <strong><span>Dean of the Faculty of Engineering and Technology Office - College of Engineering and Technology - S</span></strong>‏-‎‏‎‎<strong><span>College of Engineering and Technology </span></strong>‏.</p>
<p><strong>This certificate was issued upon </strong>‎<strong><span>her request</span></strong>‏ <strong>and without any commitment on behalf of the ORG.</strong></p>
CodePudding user response:
String html;
using (StreamReader reader = new StreamReader($@"D:\OneDrive\Dokumentumok\Projects\html.txt")) {
html = reader.ReadToEnd();
}
Int32 index = html.IndexOf("<div id=\"dv_sign_");
html = html.Substring(0, index);
index = html.LastIndexOf("<div>");
html = html.Substring(0, index);