模仿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>
以上代码参考网络资源,只供学习

你可能感兴趣的:(string.Format)