现在的位置: 首页 > 综合 > 正文

留言板 内容 格式

2012年08月26日 ⁄ 综合 ⁄ 共 1673字 ⁄ 字号 评论关闭

using System;
using System.Text;
using System.Web;

namespace Bas
{
 /// <summary>
 /// Summary description for BasFun.
 /// </summary>
 public class BasFun
 {
  public BasFun()
  {
  }

  public  string TextToHtml(string chr)
  {
   if (chr == null)
   {
    return "";
   }
            chr = chr.Replace(" ", "&nbsp;&nbsp;");
   chr = chr.Replace("<", "&lt;");
   chr = chr.Replace(">", "&gt;");
   chr = chr.Replace("\n", "<br>");
            chr = chr.Replace("\t", "&nbsp;&nbsp;&nbsp;");
            chr = chr.Replace("'","'");
   return chr;
  }

        public string HtmlToText(string chr)
        {
            if (chr == null)
            {
                return "";
            }
            chr = chr.Replace("&nbsp;", " ");
            chr = chr.Replace("&lt;", "<");
            chr = chr.Replace("&gt;", ">");
            chr = chr.Replace("<br>", "\n");
            chr = chr.Replace("&nbsp;&nbsp;&nbsp;", "\t");
            chr = chr.Replace("'","'");
            return chr;
        }
        protected string Output(object inputString)
        {
            if (inputString == null)
                return string.Empty;

            StringBuilder strBuilder = new StringBuilder();
            string str1 = HttpContext.Current.Server.HtmlEncode(inputString.ToString());
            strBuilder.Insert(0, str1);
            strBuilder.Replace(((char)32).ToString(), "&nbsp;");
            strBuilder.Replace(((char)9).ToString(), "&nbsp;");
            strBuilder.Replace(((char)34).ToString(), "&quot;");
            strBuilder.Replace(((char)39).ToString(), "'");
            strBuilder.Replace(((char)13).ToString(), " ");
            strBuilder.Replace(((char)10).ToString() + ((char)10).ToString(), "</P><P>");
            strBuilder.Replace(((char)10).ToString(), "<BR>");

            return strBuilder.ToString();
        } 
     
 }
}

抱歉!评论已关闭.