欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Asp.Net中文本换行

程序员文章站 2023-11-09 17:45:40
刚刚入门学习asp.net的朋友,都会碰到把大量带有换行文本的内容显示时,不会自动换行的问题。本人现在把解决这一问题真正有效的办法告诉大家,共同学习: 在vb.net中:...
刚刚入门学习asp.net的朋友,都会碰到把大量带有换行文本的内容显示时,不会自动换行的问题。本人现在把解决这一问题真正有效的办法告诉大家,共同学习:
在vb.net中:
1    function htmlcode()function htmlcode(byval fstring)
2        if fstring <> "" then
3            fstring = replace(fstring, chr(13), "")
4            fstring = replace(fstring, chr(10) & chr(10), "</p><p>")
5            fstring = replace(fstring, chr(10), "<br>")
6            htmlcode = fstring
7        end if
8    end function
9
使用范例:
contenttxt.text = htmlcode(rs.item("newscontent"))
注:.contenttxt为label标签控件;rs.item("newscontent")为读取数据库表中的记录集。
以上代码可在我的.net博客系统中找到详细代码。
在c#中:
   private string htmlcode(string tstring)
    {
        if (tstring != null)
        {
            tstring = tstring.replace("\r", "<br>");
            tstring = tstring.replace(" ", " ");
            return tstring;
        }
        else
        {
            return tstring="无内容";
        }
    }
使用范例:
this.contenttxt.text = htmlcode(newstab.rows[0]["contenttxt"].tostring());
注:.contenttxt为label标签控件;newstab.rows[0]["contenttxt"].tostring()为读取数据库表中的记录集。
以上代码可在我的.net新闻系统中找到详细代码。
http://lixyvip.cnblogs.com/archive/2006/03/30/362593.html