×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Arturo Bardelli
Added: May 4, 2016 3:11 PM
Modified: May 4, 2016 3:13 PM
Views: 7
  1. String.prototype.format=String.prototype.f=function(){for(var n=this,t=arguments.length;t--;)n=n.replace(new RegExp("\\{"+t+"\\}","gm"),arguments[t]);return n};
  2.  
  3. //usage
  4. var url = "/myUrl.aspx?p1={0}&p2={1}";
  5. var myUrlFormatted = url.format("value1","value2");
  6.  
  7. //myUrlFormatted will be "/myUrl.aspx?p1=value1&p2=value2";