public static StripHtml ( string strVar, bool convertBreaks, bool keepLinks ) : String | ||
strVar | string | String to process. |
convertBreaks | bool |
/// " and " " to \r\n and converts "" to \r\n\r\n. /// ]]> /// |
keepLinks | bool | Keep and anchor tags intact. |
Résultat | String |
public static String StripHtml(string strVar, bool convertBreaks, bool keepLinks)
{
if(FixNull(strVar) == string.Empty)
{
return (strVar);
}
else
{
Regex tags = new Regex(@"<(script|style).*?>.*?</(script|style).*?>", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);
strVar = tags.Replace(strVar, "");
if(convertBreaks == true)
{
tags = new Regex(@"<br[\s]*[/]*>");
strVar = tags.Replace(strVar, "\r\n");
strVar = strVar.Replace("</p>", "\r\n\r\n");
}
if (keepLinks == true)
{
strVar = Regex.Replace(strVar, "(<)(?=/??a)", "[[[[[", RegexOptions.IgnoreCase);
}
tags = new Regex(@"<[^>]+>|</[^>]+>");
strVar = tags.Replace(strVar, "");
if (keepLinks == true)
{
strVar = strVar.Replace("[[[[[", "<");
}
strVar = strVar.Replace(" ", " ");
strVar = strVar.Replace("&edsp;", " ");
return strVar;
}
}