ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 简单实现分行输出的javascript代码

简单实现分行输出的javascript代码

原创 Linux操作系统 作者:iDotNetSpace 时间:2008-09-25 13:56:39 0 删除 编辑
 在c#里只要在字符串前加上@符号,变可以让字符串随意换行,如下代码所示:


<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->string stroutput=string.Format(@"
                    
                         你好!{0}  [ 个人信息 , 退出 ]
                    
                    
                         积分:{2}  
                    
                    
                         等级:{3}
                    
                    
                        
                    
                    
                         新短消息 {4} , 收藏夹 , 管理
                    
                    
", string.IsNullOrEmpty(userInfo.Nickname) ? userInfo.Username : userInfo.Nickname, userInfo.Password.Substring(4, 8).Trim(), userInfo.Credits, UserGroups.GetUserGroupInfo(userInfo.Groupid).Grouptitle, userInfo.Newpmcount, Urls.UserInfoAspxRewrite(userInfo.Uid));

  而javascript里是不支持字符串的换行的,所以要将stroutput这个字符串输出通常需要一行一行来,在这我用了string.Split的方法来实现避免一行一行的手工输出:


<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->        private void write(HttpContext context, string line)
        {
            line 
= line.Remove(line.Length - 1, 1);
            context.Response.Write(
string.Format("document.write(\"{0}\");\r\n",line));
        }

 


<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->                   string stroutput=string.Format(@"
                    
                         你好!{0}  [ 个人信息 , 退出 ]
                    
                    
                         积分:{2}  
                    
                    
                         等级:{3}
                    
                    
                        
                    
                    
                         新短消息 {4} , 收藏夹 , 管理
                    
                    
", string.IsNullOrEmpty(userInfo.Nickname) ? userInfo.Username : userInfo.Nickname, userInfo.Password.Substring(4, 8).Trim(), userInfo.Credits, UserGroups.GetUserGroupInfo(userInfo.Groupid).Grouptitle, userInfo.Newpmcount, Urls.UserInfoAspxRewrite(userInfo.Uid));
                    
string[] aroutput =stroutput.Split('\n');
                    
foreach (string temp in aroutput)
                    {
                        write(context, temp);
                    }

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-464308/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    2376
  • 访问量
    5765987