如何逐段拆分HTML字符串

时间:2014-10-22 11:31:27

标签: c# html

我有一个HTML字符串,如下所示

<p  style="font-family: Times New Roman;"><span class="cs5efed22f1">HARRISBURG - gov today issued a consumer alert about an apparent scam concerning the Affordable Care Act. In recent days, people across the country have received calls asking for personal information, in order to obtain a "national medical card" from the government. No such card exists.</span>
</p>
<p  style="font-family: Times New Roman;"><span class="cs5efed22f1">"Do not ever give out personal, health care or bank account information over the phone, unless you initiated the call and you know who is on the other end," said Kane.</span>
</p>
<p  style="font-family: Times New Roman;"><span class="cs5efed22f1">Kane says if someone calls, offering to help you obtain this nonexistent national medical card, you should call the AG's Health Care Hotline at (877) 888-4877.  Any information you can provide-- such as the name, telephone number, or location of the caller-- will be very helpful.</span>
</p>
<p ><span  class="cs5efed22f1"><span style="font-family: Times New Roman;">You can learn more about this (and other scams) by visiting the gov's website at</span>
    <a href="http://www.example.org/"><span class="cs61a9f7db1" style="color: rgb(0, 0, 255); font-family: Times New Roman;">http://www.example.org</span>
    </a><span style="font-family: Times New Roman;">.</span></span>
</p>
<p ><span class="cs5efed22f1"><span style="font-family: Times New Roman;">The Health Care Section of the test General's website can be found here:</span>
    <a href="http://www.example.org/complaints.aspx?id=458"><span class="cs61a9f7db1" style="color: rgb(0, 0, 255); font-family: Times New Roman;">http://www.example.org/complaints.aspx?id=458</span>
    </a>
    </span>
</p>

需要在C#的第一段之后添加一些额外的HTML。

如何基于 p 标记拆分HTML字符串,并在第一段或第二段之后插入更多HTML?

1 个答案:

答案 0 :(得分:1)

尝试使用yourHtmlString.IndexOf("</p>"),它会为您提供</p>第一次出现的索引,然后在yourHtmlString.Insert()

中使用此索引