如何从ASP.NET中的HTML编辑器内容中删除div标签 [英] How to remove div tag from html editor contents in asp.net

查看:105
本文介绍了如何从ASP.NET中的HTML编辑器内容中删除div标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个应用程序.在这个应用程序中,我必须将News详细信息插入Sql Databse中.为了输入Article,我使用了HTML编辑器.我的代码是:-

I am working on an application. In this application I have to insert News detail into Sql Databse.For entering Article i have used a Html editor.My code is:-

objNews.Article = Server.HtmlEncode(Regex.Replace(ckedi.Content.Trim().ToString(), "</?(div|DIV).*?>", ""));

我已经使用regex.Replace从html编辑器中的字符串中删除标签.当我在html编辑器中输入div标签时,它会删除div标签,但也会同时删除其他标签.例如:如果我输入Text as:

I have used regex.Replace to remove tag from the string in html editor.When i enter div tag into the html editor then it removes div tag but it also remove other tag also.as ex: If i enter Text as:

<p><div width="200px;"> Sachin Retires from Cricket.</div></p>

然后将文本存储为

p> Sachin Retires from Cricket./p>

此正则表达式也删除了p标签.我只想删除div标签而不是p标签.请帮助我.

This regex removes p tag also.I want to remove div tag only not p tag.Please help me.

推荐答案

尝试以下方法:

(?i)</?div[^>]*>

说明

这篇关于如何从ASP.NET中的HTML编辑器内容中删除div标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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