C# 清除文本中的HTML标签
/// <summary>
/// 清除文本中Html的标签 /// </summary> /// <param name="Content"></param> /// <returns></returns> public static string ClearHtml(string Content) { Content = Zxj_ReplaceHtml("&#[^>]*;", "", Content); Content = Zxj_ReplaceHtml("</?marquee[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?object[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?param[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?embed[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?table[^>]*>", "", Content); Content = Zxj_ReplaceHtml(" ", "", Content); Content = Zxj_ReplaceHtml("</?tr[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?th[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?p[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?a[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?img[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?tbody[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?li[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?span[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?div[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?th[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?td[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?script[^>]*>", "", Content); Content = Zxj_ReplaceHtml("(javascript|jscript|vbscript|vbs):", "", Content); Content = Zxj_ReplaceHtml("on(mouse|exit|error|click|key)", "", Content); Content = Zxj_ReplaceHtml("<\\?xml[^>]*>", "", Content); Content = Zxj_ReplaceHtml("<\\/?[a-z]+:[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?font[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?b[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?u[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?i[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?strong[^>]*>", "", Content); Content = Zxj_ReplaceHtml("</?strong[^>]*>", "", Content); Content = Zxj_ReplaceHtml(" ", "", Content); Regex r = new Regex(@"\s+"); Content = r.Replace(Content, ""); Content.Trim(); string clearHtml = Content; return clearHtml; } /// <summary> /// 清除文本中的Html标签 /// </summary> /// <param name="patrn">要替换的标签正则表达式</param> /// <param name="strRep">替换为的内容</param> /// <param name="content">要替换的内容</param> /// <returns></returns> private static string Zxj_ReplaceHtml(string patrn, string strRep, string content) { if (string.IsNullOrEmpty(content)) { content = ""; } Regex rgEx = new Regex(patrn, RegexOptions.IgnoreCase); string strTxt = rgEx.Replace(content, strRep); return strTxt; }C# 清除文本中的HTML标签的更多相关文章
- 清除文本中Html的标签
/// <summary> /// 清除文本中Html的标签 /// </summary> /// <param name="Content"> ...
- js 清除文本中的html标签
text.replace(/<[^>]+>/g,"");
- 去除富文本中的html标签及vue、react、微信小程序中的过滤器
在获取富文本后,又只要显示部分内容,需要去除富文本标签,然后再截取其中一部分内容:然后就是过滤器,在微信小程序中使用还是挺多次的,在vue及react中也遇到过 1.富文本去除html标签 去除htm ...
- python去除文本中的HTML标签
def SplitHtmlTag(file): with open(file,"r") as f,open("result.txt","w+" ...
- Android检测富文本中的<img标签并实现点击效果
本文旨在:通过点击一张图片Toast输出位置与url链接. 闲话少说,实现原理大概是酱紫的::通过正则表达式检测富文本内的图片集合并获取url,在src=“xxx” 后面添加 onclick方法,至于 ...
- 清除大文本中的html标签
public String clearHtmlText(String inputString) { if (StringUtils.isBlank(inputString)) { return &qu ...
- 过滤掉文本中的javascript标签代码
2014年1月21日 11:51:19 php代码: $content = preg_replace('#<\s*[script].*>#', '', $a);//有些攻击可以在scrip ...
- HTML中的图片标签的用法!
在HTML中<img>这个标签是定义文本中的图片标签,它的作用就比如说可以提供图片的名字.提供图片的尺寸大小和提供图片的一些图片属性,比如Alt这个属性,可以给图片一个名称来告诉朋友们.这 ...
- 如何使用JS脚本从HTML中分离图片标签与文本,替换文本中指定的内容并加粗(原创)
var html='ddfsdfsdfdsd dfsdfsdffds<img _src="http://localhost:8490/60E86EA7-FE7B-44BF-8270-4 ...
随机推荐
- [Java并发编程之美]第1章 线程基础
第1章 线程 1.1 线程与进程 进程是操作系统资源分配和调度的基本单位,但cpu资源是分配到线程的,也就是线程是CPU分配的基本单位. 线程自己的栈资源中,存放的局部变量是线程私有的,其他线程无法访 ...
- ASP.NET Core 配置与获取
目录 1,来自字典 2,来自配置文件 3,层次结构 4,映射 ASP.NET Core 中,可以使用 ConfigurationBuilder 对象来构建. 主要分为三部:配置数据源 -> Co ...
- Shell学习(二)Shell变量
一.Shell变量 变量的定义 例子: my_job="Learn Shell" PS:变量名和等号之间不能有空格!!! 命名只能使用英文字母,数字和下划线,首个字符不能以数字开头 ...
- MyBatis学习(一)初识MyBatis
一.MyBatis简介 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名 ...
- Flutter音频播放--chewie_player的基本使用
发现网络似乎没有关于简单音频播放的插件介绍,这几天找了一下,结果也都不尽人意,最后也是debug一下chewie_player插件的官方demo 先上官方demo图 官方git地址:https://g ...
- PHP绕过disable_function
PHP绕过disable_function 常规绕过 exec exec执行command命令,但是不会输出全部结果,而是返回结果的最后一行. 想得到全部的结果,可以使用第二个参数,让其输出到一个数组 ...
- springmvc 源码分析(三) -- 自定义处理器映射器和自定义处理器适配器,以及自定义参数解析器 和错误跳转自定页面
测试环境搭建: 本次搭建是基于springboot来实现的,代码在码云的链接:https://gitee.com/yangxioahui/thymeleaf.git DispatcherServlet ...
- 第三周:java面向对象部分总结(2)
<!--此处接上周--> 3.相关接口 对对象的排序,可以通过以下两种方法: 1.实现Comparable接口,重写compareTo方法: 2.Comparator<>比较器 ...
- 免费开源工作流Smartflow-Sharp v2.0
@font-face { font-family: 宋体 } @font-face { font-family: "Cambria Math" } @font-face { fon ...
- 安卓app功能或自动化测试覆盖率统计(不用instrumentation启动app)
一文带你揭秘如何采取非instrumentation启动app,打造实时统计覆盖率,一键触发覆盖率测试报告. 在上篇文章,一文带你解决Android app手工测试或者自动化测试覆盖率统计(撸代码版) ...