michaelmcgurk
michaelmcgurk

Reputation: 6509

Strip all HTML code from String with C#

I am currently pulling some data from a SQL Server database into a C# asp.net page.

I am using the following (portion of) code to ouput the HTML text that is stored in my body column:

TextLabel.Text += "<div class=\"newsEntry\">" + 
    Convert.ToString(reader2["body"]).Substring(0, 220) + 
    "...<a href='entry.aspx?ID=" + reader2["ID"] + 
    "' title=\"Read More about " + reader2["Title"] + 
    "\">Read More &raquo;</a></div>";

I'd like to strip the body value (+ Convert.ToString(reader2["body"]).Substring(0, 220) +) of all HTML inside it.

How do I achieve this with C#?

Normally with PHP, I'd use striptags.

Many thanks for any help.

Upvotes: 1

Views: 906

Answers (1)

Related Questions