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

G

Guest

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!
 
G

Guest

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
 
M

Matt Berther

Hello Nicky,

You can remove all tags with this regex:

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top