我从数据库中读出一段C语言的程序代码;
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
string strT = i.ToString() + "." + dr["textcontent"].ToString();//读出数据库中的程序代码
 strT = strT.Replace("\r\n", "<br>");//分段
  strT = strT.Replace(" ", "&nbsp");//显示空格
Label1.Text=strT;用textbox控件输入数据库中的程序代码是:#include "stdio.h"
void fun(char n,char *p)                         
{
   for(int i=0;*p='\0';i++)
   {
   if(*(p+i)==n)
   { 
   for(int j=i;*(p+j)!='\0';j++)
   {
   a[j]=i;
   }
   }
   }
}但是用上面我写那程序方法输出的C语言的代码格式有点不对:(输出如下)#include "stdio.h"
void fun(char n,char *p)                         
{  
   for(int i=0;*p='\0';i++)
   {
   if(*(p+i)==n)
   { 
   for(int j=i;*(p+j)!='\0';j++)
   {
   a[j]=i;
   }
   }
}
求高手指点怎么输出保持原来的格式呢?

解决方案 »

  1.   

    空格是&nbsp;
    和面有分号
      

  2.   

    改下错别字
    空格是&nbsp;
    后面有分号
      

  3.   

    楼上说不对哈,用上&nbsp;也没保存原有格式
    如:输入数据库的程序是:
    #include <stdio.h>
    void main()
    {
    int i=0,j=0;
    if()
    {
    if()
    {
    i++;
    }
    else
    {
               j++;
    }
    }
    else
    {
    j++;
    }
    }用label输出页面如下:
    .#include 
    void main()
    {
    int i,j;
    if()
    {
    if()
    {
    i++;
    }
    else
    {
        j++;
    }
    }
    else
    {
    j++;
    }
    }
      

  4.   

    对不起,由于csdn网页显示的问题,输入的程序格式也没原本输出,
    输入数据库的程序是这样的:
      

  5.   

    貌似是ASP.net 网页中连续的空格当做一个空格处理。
    将如何处理呢?
      

  6.   

    strT = strT.Replace(" ", "&nbsp");//显示空格
    替换后,只有一个了
      

  7.   

    strT = strT.Replace("\r\n", "<br>");//分段
    strT = strT.Replace(" ", "&nbsp;");//显示空格
    strT = strT.Replace("\t", "&nbsp; &nbsp; &nbsp; &nbsp;"); //显示制表符