html语言放到数据库中,怎样把输入的文本转换成html代码存入数据库啊
发布日期:2021-06-24 12:30:23 浏览次数:3 分类:技术文章

本文共 1288 字,大约阅读时间需要 4 分钟。

This   may   help   you...

///文本转化成html文档的cs函数:TextParser.Parser(string   text,   bool   allow)

using   System;

using   System.Text;

using   System.IO;

namespace   WebSite.Support

{

public   class   TextParser

{

public   TextParser()

{

//

//   TODO:   Add   constructor   logic   here

//

}

//Method   to   parse   Text   into   HTML

public   string   Parser(string   text,   bool   allow)

{

//Create   a   StringBuilder   object   from   the   string   intput   parameter

StringBuilder   sb   =   new   StringBuilder(text)   ;

//Replace   all   double   white   spaces   with   a   single   white   space   and    

sb.Replace( "   ", "  ");

//Check   if   HTML   tags   are   not   allowed

if(!allow)

{

//Convert   the   brackets   into   HTML   equivalents

sb.Replace( " < ", "< ")   ;

sb.Replace( "> ", "> ")   ;

//Convert   the   double   quote

sb.Replace( "/ " ", "" ");

}

//Create   a   StringReader   from   the   processed   string   of   the   StringBuilder   object

StringReader   sr   =   new   StringReader(sb.ToString());

StringWriter   sw   =   new   StringWriter();

//Loop   while   next   character   exists

while(sr.Peek()> -1)

{

//Read   a   line   from   the   string   and   store   it   to   a   temp   variable

string   temp   =   sr.ReadLine();

//write   the   string   with   the   HTML   break   tag

//Note   here   write   method   writes   to   a   Internal   StringBuilder   object   created   automatically

sw.Write(temp+ "

")   ;

}

//Return   the   final   processed   text

return   sw.GetStringBuilder().ToString();

}

}

}

转载地址:https://blog.csdn.net/weixin_32705179/article/details/117738267 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:html描述列表在线实例,HTML的列表标签
下一篇:qt android 开机启动,Qt for android 开机自启动、开机黑屏处理

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月13日 15时32分04秒