User Id :    Password :      New Member   Forgot Password  
 
How to remove html tag from string using Regex
Description This article shows how easily we can remove html tag from string using Regular Expression   No. of Views     1847
  Rating     0
Author Sumit Gupta   Posted On     04 Aug 2010
Tags ASP.NET,C#,HTML    

Sample Code   Download Code

Generally we face a problem when we want show some html data to server control like Grid View or List View. We want to remove all the html tag from our string. For example we have following html data

char *ptr;

char myString[]="abcdefg";
ptr= myString;
ptr+=5;


What string does ptr points to in the sample code above?


We want to remove all html tag from above data. So for doing this we can use a simple Regular Expression. For this we have include following namespace

Using System.Text.RegularExpression


Then use the following code

String strData = Regex.Replace(str, @"<(.|\n)*?>", string.Empty); // here str variable hold html data


Now you will get data with no html tag like following

char *ptr;
char myString[]="abcdefg";
ptr= myString;
ptr+=5;
What string does ptr points to in the sample code above?

About Author

About Author I am Sumit Gupta working in 3 Pillar Global Pvt. Ltd as Module Lead. I have 7+ year of experience in .Net technologies. I love to explore new technologies and write technical article. Sumit Gupta
No Photo
 
Country India
Company 3 Pillar Global Pvt. Ltd.
Home Page http://www.facebook.com/sumitgupta1225

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

   
Write your comment here.
Comment
Verification Code