Return to Snippet

Revision: 27697
at June 21, 2010 16:00 by glends


Initial Code
function (s, dict) {
    var i = 0;
    return s.replace(/%(?:\(([^)]+)\))?[diouxXeEfFgGcrs]/g, function (dummy, v) { return dict[v || i++]; });
}

Initial URL

                                

Initial Description
This is a script [tweeted by @gregmuellegger](http://twitter.com/gregmuellegger/status/16618146398). Example usage: Supports f("Hello %s.", ["World"]) and f("Hello %(name)s.", {name: "World"})

Initial Title
Python-like string interpolation in JavaScript

Initial Tags
javascript, python

Initial Language
JavaScript