.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Regular Expressions >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

how to display data by removing all html tags that are present in the database?

Posted By:Nabin       Posted Date: September 02, 2009    Points: 40    Category: Regular Expressions    URL: http://www.dotnetspark.com  

This C# method remove all the html tags from the string using regular expression.
 

How to display data by removing all html tags that are present in the database. This method remove all the html tags from the string using regular expression.

public static string StripHtml(string html, bool allowHarmlessTags)
{
    if (html == null || html == string.Empty) 
        return string.Empty; 
    if (allowHarmlessTags) return System.Text.RegularExpressions.Regex.Replace(html, "", string.Empty); 
    return System.Text.RegularExpressions.Regex.Replace(html, "<[^>]*>", string.Empty);
}

Calling

txtDescription.Text = StripHtml(rdProduct["desc"].ToString(),false);

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend