ali raza

C#, .Net ,Asp.net and my thoughts

how to remove Html tags from string in c#

use this function

public string Strip(string text)
{
    return Regex.Replace(text, @”<(.|\n)*?>”, string.Empty);
}

27 responses to “how to remove Html tags from string in c#

  1. Zia Ahmed Shaikh December 10, 2007 at 6:42 pm

    Thanks Ali Raza, This post really helped me.

    Thanks once again, Let me know if i could help you in any regard.

  2. Dijin February 22, 2008 at 6:29 am

    Thanks a lot Ali Raza .A simple and amazing solution to my problem.

  3. Katia February 28, 2008 at 3:56 pm

    Perfect! Very useful!

  4. gohary May 16, 2008 at 11:08 pm

    thank you very much aliraza. very helpful tip.

  5. baurdotnet May 22, 2008 at 5:26 am

    some another way:

    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);
    }

  6. Pingback: Remove HTML Tags From a String « Baurdotnet’s Weblog

  7. altaf June 16, 2008 at 11:29 am

    thanks.
    this is very usefull

  8. Kamal August 18, 2008 at 9:22 am

    Thank you very much!! This has been hassling me for 2days and you put an end to it! Thanks again!

  9. krishna August 20, 2008 at 6:08 am

    Thanks a lot, its a gr8 help to my problem.

  10. Umair Hafeez August 27, 2008 at 11:28 am

    Great. Thumbs Up 🙂

  11. cheers September 18, 2008 at 8:23 am

    thanks Ali, simple solution…. nice

  12. dhil October 2, 2008 at 8:45 pm

    Thanks Aliraza.
    It really helps me… 😉

  13. Mustaque Ahmad October 26, 2008 at 7:41 am

    Thanks Ali Raza …Very help ful

  14. peter October 27, 2008 at 9:54 pm

    Remember to clean out things like ‘&nbsp’ or replace them with their plain text value if you are trying to get a plain text string. This regex doesn’t handle those.

  15. mac November 13, 2008 at 7:05 pm

    Great tip. Worked well for getting at the text in links that may or may not have images inside the tags.

  16. Asma Qureshi December 24, 2008 at 6:42 pm

    Thanks Ali Raza …Very nice..

  17. Eldhose.K.Joy January 13, 2009 at 4:53 am

    Very good solution. Great thinking

  18. actualal March 20, 2009 at 9:55 am

    Aces that Ali – great solution

  19. MAX April 16, 2009 at 1:05 am

    salam
    tanx . very nice and interesting.

  20. mURALI April 16, 2009 at 8:43 am

    VERY GOOD SOLUTION tHANKS ALI….

  21. Leasing IT May 7, 2009 at 2:00 pm

    Great!
    One line of code and it saves lots of time 😉

  22. Deepan May 19, 2009 at 6:47 pm

    Thanks aliraza

  23. quanghuy May 28, 2009 at 7:35 am

    Thank so much.

  24. metal July 22, 2009 at 11:36 pm

    a very useful article, 10x

  25. Yaniv Shmuel August 21, 2009 at 4:24 am

    Thanks aliraza,
    it very halpfull to me

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: