KARPACH

WEB DEVELOPER BLOG

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

Comments

Posted on 6/10/2010 02:51:48 AM by Ashish kumar

Not enough information

Posted on 11/28/2011 01:14:45 AM by fize

good one