Laith Zraikat
I Innovate, Therefore I Am.
Strip HTML tags from a string in .NET
The best and shortest way is to use Regular Expression for this task:

VB.Net

Function StripHTMLTags(ByVal HTMLToStrip AsString) AsString
Dim stripped AsString
If HTMLToStrip <> "" Then
stripped = Regex.Replace(HTMLToStrip, "<(.|\n)+?>", String.Empty)
Return stripped
Else
Return ""
EndIf
EndFunction


C#

privatestring StripHTMLTags(string HTMLToStrip)
{
string stripped;
if (!Convert.ToBoolean(HTMLToStrip == ""))
{
stripped = Regex.Replace(formHTML.Text, @"<(.|\n)*?>", string.Empty);
return stripped;
}
else
{
return"";
}
}







Add a Comment

On December, 19, 2005 9:06 AM , Rajkumar said:

This is really handy. But this also strips a simple text like <abc>

On October, 21, 2008 4:30 PM , dev said:

To remove particular HTML tag
see here
http://urenjoy.blogspot.com/2008/10/remove-html-tags-from-string.html

On October, 21, 2008 5:50 PM , laithz
from Jordan said:

Thank you.



Add a Comment

<<Home