在用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. linux下安装telnet(centos7)

    1 环境 centos 7 yum已配置好 网络连接正常 2 检查是否已安装相关软件 rpm -qa|grep telnet 3 安装相关组件 yum install xinetd yum insta ...

  2. HDFS常见问题

    在HDFS里面,data node上的块大小默认是64MB(或者是128MB或256MB) 问题: 为什么64MB(或128MB或256MB)是最优选择? 为什么不能远少于64MB(或128MB或25 ...

  3. Cisco IOS版本命名规则

    首先说说IOS的运行平台,c2500.c2600.c4500.c2950代表运行此IOS的硬件平台,例如:C2500指2500系列路由器. 其次,看看IOS的版本,IOS有主版本号:11.0.11.1 ...

  4. Java 9 逆天的十大新特性

    在介绍java9之前,我们先来看看java成立到现在的所有版本. 1990年初,最初被命名为Oak: 1995年5月23日,Java语言诞生: 1996年1月,第一个JDK-JDK1.0诞生: 199 ...

  5. EntityFramework 学习 一 Lazy Loading

    延迟加载:延迟加载相关的数据 using (var ctx = new SchoolDBEntities()) { //Loading students only IList<Student&g ...

  6. EntityFramework 学习 一 Change Tracking in Entity Framework

    EntityFramework自动跟踪上下文中已经加载的实体,DbChangeTracker类给你关于当前实体的所有跟踪信息 注意,每个实体都要有EntityKey(主键)的属性,EntityFram ...

  7. matlab之fliplr()函数

    fliplr  左右翻转矩阵 语法: B = fliplr(A) 将矩阵A的列绕垂直轴进行左右翻转 matabc 如果A是一个行向量,fliplr(A)将A中元素的顺序进行翻转. 如果A是一个列向量, ...

  8. web项目中添加logger日志

    在项目中添加log4j.xml文件 log4j.xml文件 <?xml version="1.0" encoding="UTF-8" ?><! ...

  9. 带SoapHeader验证的WebServices

    一般在项目中,制作的都是基于SOAP协议的webservices,其描述语言是WSDL.但是有时候在项目中,需要保证webservices的安全,需要对其进行进行验证,那么我们就要实现SoapHead ...

  10. GeoServer基础教程(三):部署发布Shapefile地图数据

    转载:http://blog.csdn.net/mingzai624. 这是GeoServer官方网站提供的一份Shapefile测试数据 nyc_roads.zip ,包含了部分纽约的道路信息,我们 ...