日期:2014-05-18  浏览次数:20679 次

textbox中的内容向数据库中写入时的格式问题
在把textbox中的内容向数据库中写入之后,在读出时如果用label显示他的内容,发现他的格式变了,而如果还用textbox显示就会不变,我在用label显示时,用了个函数(在网上找的):
private   string   inStr(string   oldStr)
{
    oldStr=oldStr.Replace( " ' ", " ' ' ");
    oldStr=oldStr.Replace( " < ", "&lt; ");
    oldStr=oldStr.Replace( "> ", "&gt; ");
    oldStr=oldStr.Replace( "\n ", " <br> ");
    oldStr=oldStr.Replace( "\t ", "   &nbsp;&nbsp;&nbsp; ");
    oldStr=oldStr.Replace( "\ " ", "&quot; ");
    return   oldStr;
}
显示时为:label.text=inStr(“数据库字段读出内容”);
但是用了这个函数发现格式也变,变得不多,最明显的就是第一段第一行是没有空格的,而是顶着头显示。
  请大家帮帮忙,用label来显示textbox输入的内容时,保持textbox输入是内容格式不变。  
  (textbox)是多行显示模式。

------解决方案--------------------
oldStr=oldStr.Replace( " ", "&nbsp; ");