模仿C#中的String.Format功能

 

<script type="text/javascript">
            
var str ;
            String.prototype.template 
= function()
            {
                
var args = arguments;                
                
return this.replace(/\{(\d+)\}/g,function(m,i)
                                                    {
                                                        
return args[i];
                                                    }
                                     );
            };
            
            
var a = "I Love {0}, and You Love {1},Where are {0}!";
            alert(a.template(
"You","Me"));
            
        
</script>
以上代码参考网络资源,只供学习
posted @ 2008-01-25 18:48  Sam Lin  阅读(1326)  评论(0编辑  收藏  举报