RSS

Remove HTML tags from string in c#

24 May

Remove HTML tags from string. Some time you  need to parse some string which is received by some responses like Httpresponse from the server. or when you enter from admin side in the form of htmleditor/html

then you need to show some where only plain text in short then you follow …

 

string str = “<html><head>Welcome to parse text</head><body><b>humrahimcs blog</b></body></html>”;

 

// regex which match tags

System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex(“<[^>]*>”);

 

// replace all matches with empty strin

str = rx.Replace(str, “”);

or

 

string title = rx.Replace(dr1[“Title”].ToString(), “”); ;
if (title.Length > 34)
{
newstitle.Text = title.Substring(0, 34) + “…”;
}
else
{
newstitle.Text = title;
}

 

//now str contains string without html tags like that

Welcome to parse text humrahimcs blog

 

Advertisements
 
Leave a comment

Posted by on May 24, 2013 in ASP Dot Net C#

 

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: