How to get the text in html tag.like<div...><font...>Text</font></

Discussion in 'ASP .Net' started by =?Utf-8?B?Tmlja3k=?=, Feb 20, 2005.

  1. hi, all
    I know we can do this by some jscript. But is there a way to do it in
    asp.net c# code?
    In our project, users could sumit a piece of html code and I need to remove
    all html tag out. What's the better way to do this?

    Thanks and have a wonderful holiday!
     
    =?Utf-8?B?Tmlja3k=?=, Feb 20, 2005
    #1
    1. Advertising

  2. I think by default the framework throws an exception if you enter tags in an
    input field (check out ValidateInput). But if you want to let them enter it,
    on the back end you can either use htmlEncode to make it harmless, or
    regex.replace to replace the tags with empty strings (try regexlib.com for
    examples).

    Bill

    "Nicky" wrote:

    > hi, all
    > I know we can do this by some jscript. But is there a way to do it in
    > asp.net c# code?
    > In our project, users could sumit a piece of html code and I need to remove
    > all html tag out. What's the better way to do this?
    >
    > Thanks and have a wonderful holiday!
     
    =?Utf-8?B?QmlsbCBCb3Jn?=, Feb 20, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?Tmlja3k=?=

    Matt Berther Guest

    Hello Nicky,

    You can remove all tags with this regex:

    string stripped = Regex.Replace(inputString, @"<(.|\n)*?>", String.Empty);

    --
    Matt Berther
    http://www.mattberther.com

    > hi, all
    > I know we can do this by some jscript. But is there a way to do it in
    > asp.net c# code?
    > In our project, users could sumit a piece of html code and I need to
    > remove
    > all html tag out. What's the better way to do this?
    > Thanks and have a wonderful holiday!
    >
     
    Matt Berther, Feb 20, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    959
    John C. Bollinger
    Jan 27, 2006
  2. Replies:
    1
    Views:
    424
    Andrew Thompson
    Nov 29, 2006
  3. mttc
    Replies:
    2
    Views:
    2,465
    Roedy Green
    Jul 3, 2009
  4. M Wells
    Replies:
    0
    Views:
    151
    M Wells
    Oct 6, 2004
  5. visu
    Replies:
    4
    Views:
    325
Loading...

Share This Page