How to replace question marks inside a string with the values of an array?
var s = 'Hello ?, welcome to ?';
var a = ['foo', 'bar'];
var i = 0;
alert(s.replace(/\?/g,function(){return a[i++]}));
Kind of silly to put it all on one line, but:
var str = 'Hello ?, welcome to ?',
arr = ['foo', 'bar'],
i = 0;
while(str.indexOf("?") >= 0) { str = str.replace("?", arr[i++]); }
You could use vsprintf. Although if you include sprintf, it's much more than one line.
vsprintf('Hello %s, welcome to %s', [foo, bar]);