Print this page
Saturday, 29 December 2012 13:54

how to display plain text removing all html tags

Written by 
Rate this item
(0 votes)

if you having a lot html strings,you may want to
have only plain text removing all html tags.you
can do it using REGEX

the following example shows how to do that -

string obj = "<b><i>The is test string</i></b>";
Regex regexObj = new Regex("\\<[^\\>]*\\>");
Response.Write(String.Format("<b>was: </b>{0}", obj));
// the HTML Text
obj = regexObj.Replace(obj, String.Empty);
Response.Write(String.Format("<b>now: </b>{0}", obj));
// Plain text as output

this program finds the Regex string and is replaced
with empty string.to make it more clear in
understanding,suppose a string is - "<li>test</li>"
then after the program the output will be simple
"test" as plaintext.

Read 2876 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
7