Very basic python style string variable injection - Node.js String

Node.js examples for String:Format

Description

Very basic python style string variable injection

Demo Code

/* Very basic python style string variable injection
 * /*  w w  w.  j  a v  a  2s.  c  o  m*/
 * "My name is %s, and I am %s".format("Manny", 8)  // => "My name is Manny, and I am 8"
 */
String.prototype.format = function () {
  var s = this;
  for (var i=0; i < arguments.length; i++) {
    s = s.replace( '%s', arguments[i] );
  }
  return s;
};

Related Tutorials