0

I have an HTML string as shown below

<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>

Is need to put some extra HTML after the first paragraph by C#.

How can I split the HTML string based on p tag and insert some more HTML after the first or second paragraph?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Aju Mon
  • 225
  • 2
  • 15

1 Answers1

2

Try using yourHtmlString.IndexOf("</p>") which will give you the index of the first occurence of </p>, and then use this index inside of yourHtmlString.Insert()

ojek
  • 9,680
  • 21
  • 71
  • 110
  • But what about `

    ` or `

    `, and all the other variants? The HTML you see in the real world can be very messy.

    – Jim Mischel Oct 22 '14 at 12:49
  • @JimMischel: He only said, that he want's to input something after the first paragraph. Let's not complicate something, that is simple, we can extend that later if needed. ;) – ojek Oct 27 '14 at 10:29
  • 1
    But his example clearly shows both `

    ` and `

    `. The complication is already there.

    – Jim Mischel Oct 27 '14 at 12:38