C# 只删除c上的一些html标记#
我有一个字符串:C# 只删除c上的一些html标记#,c#,html,C#,Html,我有一个字符串: string hmtl = "<DIV><B> xpto </B></DIV> string hmtl=“xpto 并且需要删除和的标记,结果是:xpto 只需和而不删除大量html标记,但保存xptohtml=Regex.Replace(html,@“”,String.Empty); 使用 如果您只是删除div标记,这将获得div标记以及它们可能具有的任何属性 var html = "<DIV>
string hmtl = "<DIV><B> xpto </B></DIV>
string hmtl=“xpto
并且需要删除
和
的标记,结果是:xpto
只需
和
而不删除大量html标记,但保存xpto
html=Regex.Replace(html,@“”,String.Empty);
使用
如果您只是删除div标记,这将获得
div
标记以及它们可能具有的任何属性
var html =
"<DIV><B> xpto <div text='abc'/></B></DIV><b>Other text <div>test</div>"
var pattern = "@"(\</?DIV(.*?)/?\>)"";
// Replace any match with nothing/empty string
Regex.Replace(html, pattern, string.Empty, RegexOptions.IgnoreCase);
var html=
“xpto其他文本测试”
var pattern=“@”(\)”;
//将任何匹配项替换为nothing/空字符串
Replace(html,pattern,string.Empty,RegexOptions.IgnoreCase);
结果
<B> xpto </B><b>Other text test
xpto其他文本测试
使用Regex
:
var result = Regex.Replace(html, @"</?DIV>", "");
你可以用普通的
<[(/body|html)\s]*>
在c#中:
var result=Regex.Replace(html,@“”);