Costa Brava Cycling Party May 2010

Wednesday, September 13, 2006

How to strip tags from a html-string

This can be done using the RegExpressions namespace : System.Text.RegularExpressions.
The standard regexpression to remove all html from a string is :


So to remove only the img tags simply change it to :



Final Code :

private string RemoveImgTags(String HtmlString)
{
Regex anyTag = new Regex(Expression);
HtmlString = Regex.Replace(HtmlString, anyTag.ToString(), string.Empty, RegexOptions.IgnoreCase);
return HtmlString;
}


More info about RegularExpressions

1 comment:

Anonymous said...

Goed bezig Jan!