也可用replace
或者
<pre>
<%=Server.HtmlEncode(strContent)%></pre>

解决方案 »

  1.   

    幕白的意思,用Replace方法,你读到一个string StringName里面,然后处理:
    StringName = StringName.Replace("OldValue","NewValue");
      

  2.   

    问题还没有解决啊,我用下面的代码可是老是提示未将对象引用设置到对象的实例。请帮我看一下究竟错在那里,最好能给我实现的代码,我刚开始学习.net,望大家多多指教!
    (需要说明的是我在前台的DataList里面放了一个ID为LabelText的Label控件,当然后台代码中添了一句protected System.Web.UI.WebControls.Label LabelText;)以下为控制格式代码:
    string strContent;
    strContent = dsNewsView.Tables[0].Rows[0][4].ToString().Trim();
    strContent = strContent.Replace(strContent,"<br>&nbsp;&nbsp;&nbsp;");
    this.LabelText.Text = strContent.Trim();
      

  3.   

    通过FindControl找到该Label,然后再操作;
      

  4.   

    newvalues=Server.HtmlEncode(oledvalue)
    还是这个好用!
      

  5.   

    控制是控制了,可是不对啊,控制的效果是每篇文章最后一行居中,其他还是没分开啊,下面是代码,请帮我看看,问题在那里啊?????????????? 深表感谢!!
    string strContent,ForStr;
    strContent = dsNewsView.Tables[0].Rows[0][4].ToString().Trim();
    ForStr = strContent ;
    ForStr.Replace(ForStr,"&vbCrLf,<br>&nbsp;&nbsp;&nbsp;&vbCrLf").ToString().Trim();
    this.LabelTEXT.Text = ForStr.Trim();
      

  6.   

    试一下   
    strContent.Replace(" ","&nbsp;").Replace("\n","<br>");
      

  7.   

    刚才用了 “  DouZHlang(飞呀飞) ” 说的,有所转变,每段分开了,但是每段最后一行还是居中!
      

  8.   

    public string ConvertText(string strText,bool bViewOrEdit)
    {
    if (bViewOrEdit)
    {
    strText = strText.Replace(((char)13).ToString(),"<br>");
    strText = strText.Replace(((char)10).ToString(),"<br>");
    strText = strText.Replace("<br><br>","<br>");
    strText =strText.Replace(" ","&nbsp;");
    }
    else
    {
    strText = strText.Replace("&nbsp;"," ");
    strText = strText.Replace("<br>",((char)13).ToString()+"<br>");
    strText = strText.Replace("<br>",((char)10).ToString());
    }
    return strText;
    }
      

  9.   

    楼上的方法和前面几位的都差不多,当bViewOrEdit为true是实现格式控制,可只是分段,每段的首行没有缩进,并且每段最后一行居中!!!!急盼高手赐教!!!!!11
      

  10.   

    改成这样:
    文本读入数据库时  .Replace("\n","<br>");从数据库读出时    .Replace(" ","&nbsp");