Thursday, September 27, 2012

Remove HTML tags from string in C#

Below is the sample code. The string contains HTML tags like below:


HTML Code:


.CS Code
protected void btnTest_Click(object sender, EventArgs e)
{
string strHtml = "
Hello World

Br Should not come.But what about this? Will this | will come? ) ";

Regex regex = new Regex("<[^>]*>");

string strWithOutHTMLTag = regex.Replace(strHtml, "");

lblResult.Text = strWithOutHTMLTag;
}

The output will come as:
"Hello World Br Should not come.But what about this? Will this | will come? )"

No comments:

Post a Comment