I've got a fairly simple method which recursively removes begining/ending html tags
class Program
{
static void Main(string[] args)
{
string s = FixHtml("<div><p>this is a <strong>test</strong></p></div>");
Console.WriteLine(s);
}
private static string FixHtml(string s)
{
//Remove any outer <div>
if (s.ToLower().StartsWith("<div>"))
{
FixHtml(s.Substring(5, s.Length - 5));
}
else if (s.ToLower().StartsWith("<p>"))
{
FixHtml(s.Substring(3, s.Length - 3));
}
else if (s.ToLower().EndsWith("</div>"))
{
FixHtml(s.Substring(0, s.Length - 6));
}
else if (s.ToLower().EndsWith("</p>"))
{
FixHtml(s.Substring(0, s.Length - 4));
}
return s;
}
}
The behaviour is that it can recursively remove the <div> & <p>
tags, but on the "return s" statement it undo's all the work, by adding back add the tags!
Anyone know why this happens? and how do i force it to return the value i want. i.e
this is a <strong>test</strong>