public string Clean(string htmlSource)
{
//The string builder will be appendend when more then 1000 corrupted tags are found.
int slack = 1000;
string correctionString = " /";
string searchedString = "<" + tagName;
StringBuilder sb = new StringBuilder(htmlSource.Length + slack);
sb.Insert(0, htmlSource);
int startIndex = 0;
int endIndex = 0;
int nonValidTags = 0;
do
{
startIndex = htmlSource.IndexOf(searchedString, endIndex);
if (startIndex >= 0)
{
endIndex = htmlSource.IndexOf('>', startIndex);
if (endIndex > 0)
{
//The tag is missing the '/' before the '>' character
if (!(htmlSource[endIndex - 1].CompareTo('/') == 0))
{
sb.Insert(endIndex + nonValidTags * correctionString.Length, correctionString);
nonValidTags++;
}
}
}
} while (startIndex < (htmlSource.Length - 1) && endIndex < (htmlSource.Length - 1) && (startIndex >= 0) && (endIndex >= 0));
return sb.ToString();
}