简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM