在用Umbraco开发项目的过程中,由于在Umbraco Back office 中有用到 rich text editor, 而它返回的值是HtmlString类型,也就是说是包含Html Tag的

比如 返回的是 "<p><span>This is a test message</span></p>"

那么,如何来移除掉其中的html tag呢.

我们可以用正则表达式来移除掉其中的html tag

@using System.Text;
@using System.Web; public static class StringTool
{ private static readonly Regex HtmlTag = new Regex(@"<[^>]*>"); public static string RemoveHtmlTag(this string origStr)
{
return string.IsNullOrEmpty(origStr) ? origStr : HttpUtility.HtmlDecode(HtmlTag.Replace(origStr, string.Empty));
} }

上面,我们写了一个扩展方法 RemoveHtmlTag 来移除string中的html tag, 采用了正则表达式HtmlTag

Remove all the html Tag in String的更多相关文章

  1. [LeetCode] Add Bold Tag in String 字符串中增添加粗标签

    Given a string s and a list of strings dict, you need to add a closed pair of bold tag <b> and ...

  2. LeetCode 616. Add Bold Tag in String

    原题链接在这里:https://leetcode.com/problems/add-bold-tag-in-string/description/ 题目: Given a string s and a ...

  3. 616. Add Bold Tag in String加粗字符串

    [抄题]: Given a string s and a list of strings dict, you need to add a closed pair of bold tag <b&g ...

  4. 【LeetCode】616. Add Bold Tag in String 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcode ...

  5. [LeetCode] 203. Remove Linked List Elements_Easy tag: Linked LIst

    Remove all elements from a linked list of integers that have value val. Example: Input: 1->2-> ...

  6. 深入探讨:标签(Tag)的各种设计方案

    首先,标签(Tag)是什么? 我的理解:用来具体区分某一类内容的标识,和标签类似的一个概念是分类(Category),有一个示例可以很好的区分它们两个,比如人类分为:白种人.黄种人和黑种人(可以看作分 ...

  7. 标签(Tag)的各种设计方案

    标签(Tag)的各种设计方案 首先,标签(Tag)是什么? 我的理解:用来具体区分某一类内容的标识,和标签类似的一个概念是分类(Category),有一个示例可以很好的区分它们两个,比如人类分为:白种 ...

  8. 没什么技术含量的Remove Before Flight

    航空业有很多值得我们借鉴和学习的工作方式,将来有时间我会给大家引荐更多实例. 仔细观察每架停泊着的飞机,会发现机身很多地方都挂着细长的红布条,上面写着"REMOVE BEFORE FLIGH ...

  9. 【LeetCode】字符串 string(共112题)

    [3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...

随机推荐

  1. 07 09&10

    0709: 排名还是不高,毕竟没切出来题. 第一题dalao: 要求你做一个三维数点,只回答最终有多少个点对的状态是完全小于(可比?)的.(n<=2000000) 特殊限制是三维都是随机排列. ...

  2. hbase shell-security(安全指令)

    hbase shell安全指令篇: grant list_security_capabilities revoke user_permission 正在编辑中

  3. kafka常用的shell命令

    kafka常用shell命令: ------------------------------------ 1.创建topic bin/kafka-topics.sh --create --zookee ...

  4. 2015年SCI收录遥感期刊28种目录

    链接地址:http://blog.sciencenet.cn/blog-57081-928025.html

  5. HTML5坦克大战1

    在JavaScript中,不要在变量为定义之前去使用,这样很难察觉并且无法运行. 颜色不对. 当我的坦克移动时,敌人坦克消失. tankGame3.html <!DOCTYPE html> ...

  6. java备份和恢复数据代码例子

    import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.F ...

  7. javascript作用域与闭包

    Javasript作用域概要 在javascript中,作用域是执行代码的上下文,作用域有三种类型: 1)  全局作用域 2)  局部作用域(函数作用域) 3)  eval作用域 var foo = ...

  8. Delphi操作XML - 冰雪傲骨

    Delphi操作XMl,只要使用 NativeXml.我是用的版本是4..NativeXML的使用方法比较简单,但是功能很强大. XE2的话,要在simdesign.inc后面加上: // Delph ...

  9. 再次理解WCF以及其通信(附加一個編程小經驗)

    一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...

  10. js修改css时如何考虑兼容性问题es5+es6

    es5的写法 var elementStyle = document.createElement('div').style var vendor = (function(){ let transfor ...