清楚文本格式

jjyy17173 2009-01-10 11:26:54
哪个好心人帮帮我,我现在的情况是这样的 ,从数据库里读取文本,但是文本读取出来带有格式的,如<P>,回车这种,
我想数据库里读取出来的文本不带这些格式,纯文本,谁能帮我解决下,谢谢
...全文
589 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hongmaohouzi 2009-01-10
  • 打赏
  • 举报
回复
up
jiang_jiajia10 2009-01-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 oec2003 的回复:]
用正则去掉html标记
/// <summary>
/// 移除Html中的标记
/// </summary>
/// <param name="html">html字符串 </param>
/// <returns>返回移除后的文本 </returns>
public static string RemoveHtml(string html)
{
html = html.ToLower();
Regex regex1 = new Regex(@" <script[\s\S]+ </script *>", RegexOptions.IgnoreCase); …
[/Quote]
挺好
oec2003 2009-01-10
  • 打赏
  • 举报
回复
用正则去掉html标记
/// <summary>
/// 移除Html中的标记
/// </summary>
/// <param name="html">html字符串</param>
/// <returns>返回移除后的文本</returns>
public static string RemoveHtml(string html)
{
html = html.ToLower();
Regex regex1 = new Regex(@"<script[\s\S]+</script *>", RegexOptions.IgnoreCase);
Regex regex2 = new Regex(@" href *= *[\s\S]*script *:", RegexOptions.IgnoreCase);
Regex regex3 = new Regex(@" no[\s\S]*=", RegexOptions.IgnoreCase);
Regex regex4 = new Regex(@"<iframe[\s\S]+</iframe *>", RegexOptions.IgnoreCase);
Regex regex5 = new Regex(@"<frameset[\s\S]+</frameset *>", RegexOptions.IgnoreCase);
Regex regex6 = new Regex(@"\<img[^\>]+\>", RegexOptions.IgnoreCase);
Regex regex7 = new Regex(@"</p>", RegexOptions.IgnoreCase);
Regex regex8 = new Regex(@"<p>", RegexOptions.IgnoreCase);
Regex regex9 = new Regex(@"<[^>]*>", RegexOptions.IgnoreCase);

html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
html = regex6.Replace(html, ""); //过滤frameset
html = regex7.Replace(html, ""); //过滤frameset
html = regex8.Replace(html, ""); //过滤frameset
html = regex9.Replace(html, "");
html = html.Replace(" ", "");
html = html.Replace("</strong>", "");
html = html.Replace("<strong>", "");
html = html.Replace(" ", "");
html = html.Replace(" ", "");

return html;
}
CodeProject-Jerry 2009-01-10
  • 打赏
  • 举报
回复
使用正则表达式替换,
比如将 <p/> 替换为 \r\n
wbqusts 2009-01-10
  • 打赏
  • 举报
回复
你把数据读出来后写到文本文件里,然后再从文本文件里读出来,这时候读出的是纯文本,没有格式
takako_mu 2009-01-10
  • 打赏
  • 举报
回复
你將XML轉換成其他格式,比如DataTable.
lambober 2009-01-10
  • 打赏
  • 举报
回复
用正则把html标签那些给干掉,网上好多代码的
jjyy17173 2009-01-10
  • 打赏
  • 举报
回复
upupupupupupupupupupupupup
jjyy17173 2009-01-10
  • 打赏
  • 举报
回复
上面的方法不的哦,我把
<palign="center">产品1产品1</p> <palign="center">产品1产品1</p> <palign="center">产品1产品1</p

这个传进去,传出来还是这个。。。


62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧