去除指定字符串中的HTML标签
来源:互联网 发布:17网络批发市场 编辑:程序博客网 时间:2024/05/22 00:35
//去除指定字符串中的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标签
- C#去除指定字符串中的HTML标签
- C#去除指定字符串中的HTML标签相关代码函数
- 去除字符串中的HTML标签
- 去除字符串中的html标签
- 去除字符串中的HTML标签
- 去除字符串中的html标签
- 猫猫学iOS之去除服务器返回数据中的html标签,去除指定字符串,替换字符串
- AJ学IOS之去除服务器返回数据中的html标签,去除指定字符串,替换字符串
- C#去除字符串中的html标签
- PHP去除字符串中的html标签
- ASP.NET去除HTML标签并截取指定长度字符串
- java去除字符串中的html标签的方法
- java字符串去除html标签
- 去除文本中的HTML标签
- 去除字符串中的Html代码
- 去除字符串中的html标记
- 去除字符串中的html格式
- 通用软件开发平台(General Software Developing Platform)设想:1
- C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(四十六)飞行模式 – 自由VS天空
- 给你一个故事,希望你能喜欢这个故事并希望它能为你带来好运
- MFC常用类及其成员函数
- 37个网页web2.0按钮色设计欣赏
- 去除指定字符串中的HTML标签
- CString 操作指南
- mschart 控件
- Can anyone able to broadcast movies
- [学习标准库]stdio.h
- 【转载】如何做一个出色的程序员
- BSTR类型
- 要毕业了
- Struts的工作流程