仅删除C#的某些HTML标记 [英] remove only some html tags on c#

查看:107
本文介绍了仅删除C#的某些HTML标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串:

string hmtl = "<DIV><B> xpto </B></DIV>

和我不会采取< D​​IV> < / DIV> ,也就是说,我的结果必然是:< B> xpto< / B>

and i wont take <div> and </DIV>, i.e, my result must be: <B> xpto </B>

感谢

继续 -

< D​​IV>和< / DIV> 是一为例,我不会删除很多html标签,但节省德< ; b> xpto< / b> 感谢

<DIV> and </DIV> was a exemple, i wont remove a lot of html tags, but save de <B> xpto </B>. thanks

推荐答案

使用正则表达式

var result = Regex.Replace(html, @"</?DIV>", "");

更新时间:

提到这段代码,正则表达式删除所有产品关键词其他 b

as you mentioned, by this code, regex removes all tages else B

var hmtl = "<DIV><B> xpto </B></DIV>";
var remainTag = "B";
var pattern = String.Format("(</?(?!{0})[^<>]*(?<!{0})>)", remainTag );
var result =  Regex.Replace(hmtl , pattern, "");

这篇关于仅删除C#的某些HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆