博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
html语言放到数据库中,怎样把输入的文本转换成html代码存入数据库啊
阅读量:1533 次
发布时间:2019-04-21

本文共 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();

}

}

}

转载地址:http://qeddy.baihongyu.com/

你可能感兴趣的文章
三年老Android经验面经,看看这篇文章吧!
查看>>
为什么Android要采用Binder作为IPC机制?成功入职腾讯
查看>>
海量算法高频面试题精编解析,附超全教程文档
查看>>
深入浅出Android性能调优,系列篇
查看>>
深入浅出Android性能调优,附大厂真题面经
查看>>
深入解析Android-AutoLayout,全网疯传
查看>>
深入解析android核心组件和应用框架,最全Android知识总结
查看>>
深入解析android核心组件和应用框架,社招面试心得
查看>>
深度解析跳槽从开始到结束完整流程,持续更新中
查看>>
深度解析跳槽从开始到结束完整流程,面试真题解析
查看>>
hashmap扩容过程,字节大神强推千页PDF学习笔记,经典好文
查看>>
kotlin面试题!Android大厂高频面试题解析,薪资翻倍
查看>>
kotlin面试题!一口气拿了9家公司的offer,已拿offer入职
查看>>
retrofit优点,互联网寒冬公司倒闭后,年薪50W
查看>>
retrofit原理面试,Android性能优化最佳实践,面试必备
查看>>
【工作感悟】Android多进程从头讲到尾,offer拿到手软
查看>>
【微信小程序】面试一路绿灯Offer拿到手软,好文推荐
查看>>
Android之内存泄漏调试学习与总结,分享PDF高清版
查看>>
安卓开发权威指南!我在美团Android研发岗工作的那5年,灵魂拷问
查看>>
【金三银四】安卓工程师跳槽经验分享,源码+原理+手写框架
查看>>