.net文章发布系统中如何把空格回车转换

来源:百度知道 编辑:UC知道 时间:2024/05/21 17:52:35
我用.net做的一个文章发布系统,后台录入文章,然后前台显示
但是显示的时候会没有格式,没有空格和回车,变成一大段

怎样实现可以直接转换过来?是在后台输入的时候用什么函数吗

this.decument.Text=this.decument.Text.Replace("&","& amp;");
this.decument.Text=this.decument.Text.Replace("<","& lt;");
this.decument.Text =this.decument.Text.Replace(">","& gt;");
this.decument.Text =this.decument.Text.Replace("'","’");
this.decument.Text=this.decument.Text.Replace( "\u000D" ,"<br>");
this.decument.Text=this.decument.Text.Replace( "\u0020" ,"& nbsp;");
------------------------------
&后面的空格要去掉
decument是文章所在的文本框。在保存之前做上面的转换。就可以了。

提取录入文章的时候进行字符转换
str.Replace("\n","<br>"); //替换回车
str.Replace(" "," "); //替换空格

后台HTML编辑就好了啊