去除指定字符串中的HTML标签
//去除指定字符串中的HTML标签相关代码函数
private static string RemoveHtml(string strContent, string strTagName)
{
string pattern = "";
string strResult = "";
Regex exp;
MatchCollection matchList;
//去掉所有<a></a>两个标记的内容,保留<a>和</a>代码中间的代码
pattern = "<" + strTagName + "([^>])*>";
exp = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
matchList = exp.Matches(strContent);
foreach (Match match in matchList)
{
if (match.Value.Length > 0)
{
strResult = match.Value;
strContent = strContent.Replace(strResult, "");
}
}
pattern = "</" + strTagName + "([^>])*>";
exp = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
matchList = exp.Matches(strContent);
foreach (Match match in matchList)
{
if (match.Value.Length > 0)
{
strResult = match.Value;
strContent = strContent.Replace(strResult, "");
}
去掉所有<a></a>和两个标记之间的全部内容
pattern = "<" + strTagName + "([^>])*>.*?</" + strTagName + "([^>])*>";
exp = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
matchList = exp.Matches(strContent);
foreach (Match match in matchList)
{
if (match.Value.Length > 0)
{
strResult = match.Value;
strContent = strContent.Replace(strResult, "");
}
}
}
return strContent;
}
相关文档:
一 HTML的定义
HTML(HyperText Mark-up Language)即超文本标记语言或超文本链接标示语言,是目前网络上应用最为广泛的语言,也是构成网页文档的主要语言。HTML文本是由HTML命令组成的描述性文本,HTML命令可以说明文字、图形、动画、声音、表格、链接等。HTML的结构包括头部(Head)、主体(Body)两大 ......
HTML英语意思是:Hypertext Marked Language,即超文本标记语言,是一种用来制作超文本文档的简单标记语言。用HTML编写的超文本文档称为HTML文档,它能独立于各种操作系统平台(如UNIX,WINDOWS等)。自1990年以来HTML就一直被用作World Wide Web 的信息表示语言,用于描述Homepage的格式设计和它与WWW上其它Homepage 的连结 ......
有时候我们需要在Flex应用中嵌入HTML代码,根据嵌入HTML要求的不同有以下两种方法:
1、Flex文本组件(Label、Text、TextArea)的htmlText属性支持一些基本的HTML代码,例如:
<mx:TextArea>
<mx:htmlText>
<![CDATA[
<p alig ......
W3C 在 1 月 22 日发布了最新的 HTML 5 工作草案。 HTML 5 工作组包括 AOL, Apple, Google, IBM, Microsoft, Mozilla, Nokia, Opera 以及数百个其他的开发商。 HTML 5 中的一些新特性:嵌入音频、视频、图片的函数、客户端数据存储,以及交互式文档。其他特性包括新的页面元素,比如 <header>, <section>, &l ......
1、文本标签(命令)
<pre></pre> 创建预格式化文本
<h1></h1> 创建最大的标题
<h6></h6> 创建最小的标题
<b&g ......