How to strip HTML tags using regular expressions in .NET?

I use following method to make short descriptions from HTML content.

It strips HTML tags and takes specified length from 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;

}


Wednesday, March 19, 2008 | Comments (1) | Add Comment

Comments

Gravatar

Re:How to strip HTML tags using regular expressions in .NET?

Not enough information

6/10/2010 2:51:48 AM | by Ashish kumar

New Comment

Your Name:
Email (for internal use only):
Subject:
Comment:
 
Code above:

Categories

Recent Tweets

Valid XHTML 1.0 Transitional