How to strip HTML tags using regular expressions in .NET?
I use the following method to make short descriptions from HTML content.
It strips HTML tags and takes a specified length from the passed content.
public static string Ellipsis(this string text, int length)
{
string s = Regex.Replace(text, @"\<[^\>]*\>", "");
if (lenght > 3 && lenght < s.Length)
if (lenght - 3 < s.Length)
return s.Substring(0, lenght - 3) + "...";
return s;
}
Posted on March 19, 2008 by Viktar Karpach