TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Remove Tags from String in C#
Parminder Pal Singh
Dec 18
2014
Code
12.9
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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