C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Remove Tags from String in C#
WhatsApp
Parminder Pal Singh
Dec 18
2014
13.2
k
0
1
Sometimes we get error in string variable because of html tags in string. There is simple and easier way to remove html tags from string. There is a few lines of code which will help you to remove tags from string.
using
System.Text.RegularExpressions
//Firstly, you have to add one namespace.
string
strWithHtml =
"<h1>Sample</h1> p> Hello this is a sample text with html tags. Code will remove all the tags from text.</p>"
;
// string with html tags
string
noHTML = Regex.Replace(strWithHtml, @
"<[^>]+>| "
,
""
).Trim();
Response.Write(noHTML);
Tags
C#
Tags
Remove Tags
Up Next
Remove Tags from String in C#