strip tags in asp.net

Last post 11-06-2009 10:42 AM by john lockwood. 7 replies.

Sort Posts:

  • strip tags in asp.net

    07-12-2005, 12:01 PM
    • Member
      85 point Member
    • filbahere
    • Member since 05-19-2005, 8:07 AM
    • Posts 17
    hi is there any why to strip tags from html in asp.net
    as the abstract column we use in search , normally shows faulty tags results.
    as far as i have seen on the net
    i havn't found any proper function to remove every tag as we can see in php striptag removes all the html tags but asp.net is not able to do so.


    plz help me out
  • Re: strip tags in asp.net

    08-29-2005, 10:54 PM
    • Member
      25 point Member
    • ilikemonkeys
    • Member since 07-21-2005, 2:16 AM
    • Posts 5
    It's something like this:

    System.Text.RegularExpressions.Regex.Replace(Server.HtmlDecode(strHTMLText), @"(\<[^\<]*\>)

    Pretty messy, I know. Can you post back here if you find a better way?

  • Re: strip tags in asp.net

    10-02-2007, 6:58 AM
    • Member
      168 point Member
    • er.tushar
    • Member since 01-21-2006, 4:46 PM
    • India
    • Posts 40

    Stripped = Regex.Replace(HtmlContent, @"<(.|\n)*?>", string.Empty);

    Regards,
    Tushar
  • Re: strip tags in asp.net

    11-21-2008, 1:36 AM
    • Member
      14 point Member
    • AndreiR23
    • Member since 09-17-2006, 9:47 PM
    • Bucharest, Romania, Europe
    • Posts 9
    Have a look on my own implementation of the PHP's strip_tags function in ASP.NET here -> http://www.codeproject.com/KB/MCMS/htmlTagStripper.aspx
    Filed under:
  • Re: strip tags in asp.net

    11-27-2008, 10:44 AM
    • All-Star
      62,877 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,279
    • TrustedFriends-MVPs

     >i havn't found any proper function to remove every tag as we can see in php striptag removes all the html tags but asp.net is not able to do so.

    In what circumstances are you wanting to strip tags? If it is check some HTML input by a user, there is an IsValidHtmlFragment function in the common data project at  http://www.CodePlex.Com/CommonData

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: strip tags in asp.net

    02-02-2009, 12:22 PM
    • Member
      2 point Member
    • mnotpit
    • Member since 02-02-2009, 5:13 PM
    • Posts 1

    One of the easiest ways to strip tags in .NET is to use the HTML Web Control objects themselves. All you really need to do is insert your string into a temporary HTML object such as a DIV, then use the built-in 'InnerText' to grab all text that is not contained within tags. See below for a simple C# example:

    System.Web.UI.HtmlControls.HtmlGenericControl htmlDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
    htmlDiv.InnerHtml = htmlString;
    String plainText = htmlDiv.InnerText;
    http://www.wiredviews.com: Custom Web-based Application Development
    Filed under: , , , , , ,
  • Re: strip tags in asp.net

    11-05-2009, 11:29 AM


    mnotpit:

    One of the easiest ways to strip tags in .NET is to use the HTML Web Control objects themselves. All you really need to do is insert your string into a temporary HTML object such as a DIV, then use the built-in 'InnerText' to grab all text that is not contained within tags. See below for a simple C# example:

    System.Web.UI.HtmlControls.HtmlGenericControl htmlDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
    htmlDiv.InnerHtml = htmlString;
    String plainText = htmlDiv.InnerText;

    good

    I was looking for along time for such solution ,because reguler exprissions not work fine with all cases


  • Re: strip tags in asp.net

    11-06-2009, 10:42 AM
    • Member
      2 point Member
    • john lockwood
    • Member since 09-12-2009, 2:01 AM
    • Posts 1

    @mnotpit.  Very cool -- I'm going to try that.

    John Lockwood
    ParticleWave Software Development
Page 1 of 1 (8 items)