mwhite14
mwhite14

Reputation: 257

Removing a Selective Section from a String

I need help figuring out how to remove only the very last "</span>" tag from a string. He is an example of what one of the strings might look like, but sometimes there are a few

<DIV style="TEXT-ALIGN: center"><span style="text-decoration:underline;"> some text   </span> </span></DIV> 

Upvotes: 1

Views: 146

Answers (2)

paul
paul

Reputation: 22001

        var originalString = @"<DIV style='TEXT-ALIGN: center'><span style='text-decoration:underline;'> some text   </span> </span></DIV>";

        var lastIndex = originalString.LastIndexOf("</span>");

        var newwString = originalString.Substring(0, lastIndex) + originalString.Substring(lastIndex + 7);

Upvotes: 1

burning_LEGION
burning_LEGION

Reputation: 13450

use this regex </span>(?=[(</span>)])

Upvotes: 0

Related Questions