C#清除HTML样式

需求说明:

网站开发时我们经常用一个富文本控件让用户自己编辑新闻内容和新闻格式,然后将HTML代码一并保存到数据库中。

然后显示文章列表的时候只需要显示一个文章摘要,所以我们就计划将文章内容截取前面50个字符作为摘要,不过这个摘要需要去除文章里面的HTML样式,所以最后我们采用正则表达式处理,使用方式如下:

public string striphtml(string strhtml)
{
    string stroutput = strhtml;
    Regex regex = new Regex(@"<[^>]+>|</[^>]+>");
    stroutput = regex.Replace(stroutput, "");
    stroutput = new Regex(@"(&nbsp;)+").Replace(stroutput, " ");
    return stroutput;
}
时间: 2024-08-07 16:09:34

C#清除HTML样式的相关文章

表单单选多选项清除默认样式小技巧

工作中做项目都会遇到表单 单选.多选项的样式问题,对于一个刚入行的菜鸟来说,可能不知道如何修改很low的选项默认样式,下表给初学者提供了改变默认样式的小技巧 首先要清除默认样式,非常简单的css: input{-webkit-user-select:text;-ms-user-select:text;user-select:text;-webkit-appearance:none;font-size:1em;line-height:1.5em;list-style:none;} input{ou

CSS 清除默认样式

CSS 清除默认样式 通常有以下几句就够了: *{ margin:0; padding:0 } li{ list-style:none } img{ vertical-align:top; border:none } 如果你想写全也可以: /* 清除内外边距 */ body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, /* structural elements 结构元素 */ dl, dt, dd, ul, ol, li, /* list eleme

【荐】万能清除浮动样式

这个是一个很流行的清除浮动的方法,在很多大项目上已经被完全采用. 这个方法来源于positioniseverything ,通过after伪类:after和IEhack来实现,完全兼容当前主流浏览器. <style type="text/css"> .clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; } .clearfix

jquery 清除嵌入式样式

1 /*有些页面样式不规范,没有写在一个class里,例如:<div id="show" style="width:100px; padding-top:10px; font-size:12px;"></div> 2 */ 3 4 //这种情况下清空style可以removeAttr()方法移除style属性来实现 5 6 $("#show").removeAttr("style"); //ie,ff均

5.清除默认样式_reset.css

body,ul,ol,li,p,h1,h2,h3,h4,h5,h6,form,fieldset,table,td,img,div,dl,dt,dd,input{ margin: 0; padding: 0; } body{font-family: "Microsoft YaHei";font-size:12px;} img{border:none;} li{list-style:none;} input,select,textarea{outline:none;} a{text-dec

清除默认样式

body, ul, ol{ margin: 0px; padding: 0px; } ul, ol{ list-style: none; } a{ text-decoration: none; }

jquery 清除style样式

$("#show").removeAttr("style"); //ie,ff均支持 $("#show").attr("style",""); //ff支持,ie不支持 $("p:first").removeClass("intro");  

清除浮动样式

.clearFix:after { content: ''; display: block; clear: both; } .clearFix { zoom: 1; } 原文地址:https://www.cnblogs.com/wensx/p/11963331.html

清除浏览器自带样式

HTML默认样式html, address,blockquote,body, dd, div,dl, dt, fieldset, form,frame, frameset,h1, h2, h3, h4,h5, h6, noframes,ol, p, ul, center,dir, hr, menu, pre { display: block }/*以上列表元素默认状态下一块状显示,未显示的将以内联元素显示,该列表针对HTML4版本,部分元素在XHTML1中将废弃*/li { display: l