通过TextBox输入多行文本,文本分出了段落格式。
但是在通过HTML文本显示时候,格式不见了
请问怎么处理啊,急。

解决方案 »

  1. string retVal=inputString;
    retVal=retVal.Replace("&","&"); 
    retVal=retVal.Replace("\"","""); 
    retVal=retVal.Replace("<","&lt;"); 
    retVal=retVal.Replace(">","&gt;"); 
    retVal=retVal.Replace(" ","&nbsp;"); 
    retVal=retVal.Replace("  ",""); 
    retVal=retVal.Replace("\t","");
    retVal=retVal.Replace("\r", "<br>");
      

  2. string retVal=inputString;
    retVal=retVal.Replace("&","&amp;"); 
    retVal=retVal.Replace("\"","&quot;"); 
    retVal=retVal.Replace("<","&lt;"); 
    retVal=retVal.Replace(">","&gt;"); 
    retVal=retVal.Replace(" ","&nbsp;"); 
    retVal=retVal.Replace("  ",""); 
    retVal=retVal.Replace("\t","");
    retVal=retVal.Replace("\r", "<br>");
      

  3. string retVal="";
    retVal=retVal.Replace("&","&amp;"); 
    retVal=retVal.Replace("\"","&quot;"); 
    retVal=retVal.Replace("<","&lt;"); 
    retVal=retVal.Replace(">","&gt;"); 
    retVal=retVal.Replace(" ","&nbsp;"); 
    retVal=retVal.Replace("  ",""); 
    retVal=retVal.Replace("\t","");
    retVal=retVal.Replace("\r", "<br>");
      

  4. 显示的时候用<pre></pre>包着显示内容就能保持格式了
      

类似问题 »