如何从字符串中删除HTML标记 [英] How to remove HTML tags from a string
本文介绍了如何从字符串中删除HTML标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
protected void grdStepMain_RowDataBound( object sender,GridViewRowEventArgs e)
{
int i = 0 ;
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell cell in e.Row.Cells)
{
i ++;
string description = cell.Text;
if (cell.Text.Length > 8 &&(i == 2 ))
cell.Text = cell.Text.Substring( 0 , 8 )+ ....跨度>;
string newdescription = Regex.Replace(description, @ < [^>] +> |, )。修剪();
cell.ToolTip = newdescription;
}
}
}
但它无法从字符串中删除标签。如何删除它??
结果看起来像::< strong> vvvvv< / strong> vvvvvvvvvv
任何人都可以帮助
解决方案
试试这个... < br $> b $ b
string noHTML = Regex.Replace(inputHTML, @ < [^>] +> |, )。修剪();
或
参考:从字符串中删除HTML标记,包括 在C#
检查出来: http://www.dotnetperls .com / remove-html-tags [ ^
This is my code
protected void grdStepMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell cell in e.Row.Cells)
{
i++;
string description = cell.Text;
if (cell.Text.Length > 8 && (i == 2))
cell.Text = cell.Text.Substring(0, 8) + "....";
string newdescription = Regex.Replace(description, @"<[^>]+>| ", "").Trim();
cell.ToolTip = newdescription;
}
}
}
but it couldn't removes the tags from the string.How to remove it??
result looks like :: <strong>vvvvv</strong>vvvvvvvvvv
could anyone help pls
解决方案
Hi,
Try this...
string noHTML = Regex.Replace(inputHTML, @"<[^>]+>| ", "").Trim();
Check this out: http://www.dotnetperls.com/remove-html-tags[^]
这篇关于如何从字符串中删除HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文