Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace the last occurence of the character in .net

i want to replace the last occurence of <li> to add class inside it, it should look like below. <li class="last">

<li><span>Vislink Acquires Gigawave for US$6 Million </span></li>
<li><span>Newegg Offers $25 7-inch DTV</span></li>
<li><span>The Hope of Broadcasters  </span></li>
<li><span>ICANN Approves Custom Domain Extensions  </span></li>
<li><span>Sciences Ending U.S. Sales  </span></li>
<li><span>LightSquared Proposes Plan to  </span></li>
<li><span>Wimbledon Gets 3D upgrade </span></li>
<li><span>The Hope of Broadcasters  </span></li>
<li><span>LightSquared Proposes Plan to  </span></li>
<li class="last"><span> Newegg Offers $25 7-inch DTV  </span></li>

i have stored the above html in a string variable. what could i do to achieve this.

like image 217
Abbas Avatar asked Dec 06 '22 18:12

Abbas


1 Answers

If you are doing this in code behind, which is what I perceive to be the case, try someting like:

    var last = htmlString.LastIndexOf("<li>");
    htmlString = htmlString.Remove(last, 4).Insert(last, "<li class=\"last\"");
like image 69
Adam Barney Avatar answered Jan 07 '23 04:01

Adam Barney