I various string objects with html formatted text. Some of these strings contain certain tags at the end that I want to remove programmatically, like these linebreak and paragraph tags at the end:
<li><ol> **Text/List** </li></ol><p><br></p><br><br>
I need to check the string from its endpoint, but I can't figure out where to cut the end off, or where to look for the cutting point. I just need to get rid of these redundant tags.
I tried to build a function that checks the string, I know it doesn't work properly, but it's my basis:
public static String RemoveRedundantTags(this String baseString, String html)
{
if (html.Contains("<"))
{
for (Int32 i = html.Length - 1; i >= 1; i--)
{
if (html[i] == '<' && html[i - 1] != '>' && html[i + 1] != '/')
{
redundantTags = html.Substring(html[i], html.Length - i);
html = html.Replace(redundantTags, String.Empty);
return html;
}
}
}
return html;
}
htmlstring.Replace("<br>","").Replace("<p>","").Replace("</p>","");or something like that?