Sunday, March 11, 2012

How to remove HTML tag

 

Below code remove the HTML tag. It removes HTML tag from your string.

public string RemoveHtmlTag(string html, bool allowHarmlessTags)

{

if (html == null || html == string.Empty)

return string.Empty;

 

if (allowHarmlessTags)

return System.Text.RegularExpressions.Regex.Replace(html, "", string.Empty);

 

return System.Text.RegularExpressions.Regex.Replace(html, "<[^>]*>", string.Empty);

//return html;

}

 

public string RemoveHtmlTagSearch(string html)

{

if (html == null || html == string.Empty)

return string.Empty;

 

return System.Text.RegularExpressions.Regex.Replace(html, "<[^>]*>", string.Empty);

 

}