• We just launched and are currently in beta. Join us as we build and grow the community.

How to Remove HTML Tags ASP.NET(C#)

ruicvc

Code Refactorer
R Rep
0
0
0
Rep
0
R Vouches
0
0
0
Vouches
0
Posts
134
Likes
192
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Submitted by
planetsourcecode

on
Sat, 06/13/2009 - 15:13

In some conditions we have to remove the HTML tags like
etc to be removed and stored the same text into a simple text form.Take an example of comment

user form in website where the user is also inputing some HTML tags in the comment section and we want to remove that tags so we can save that data into our

database.We can handle that situation very easily by using the function "RemoveHTMLTags" where are doing it with regular expression

protected void Page_Load(object sender, EventArgs e)
{
string str = "Code platter software developers";
Response.Write(RemoveHTMLTags(str));
}
public string RemoveHTMLTags(string source)
{
string expn = ".*?>";
return Regex.Replace(source, expn, string.Empty);
}

note: Include System.Text.RegularExpressions namespace for the above code to work.
-----------------------------------------------
About the author:

PlanetSourceCode.in is a place for all developer providing free source codes, articles, complete projects,complete application in PHP, C/C++, Javascript, Visual Basic, Cobol, Pascal, ASP/VBScript, AJAX, SQL, Perl, Python, Ruby, Mobile Development
-----------------------------------------------

 

437,153

314,794

314,803

Top