String.format for javascript (C# .NET like syntax for concatenating strings)

Here is a little hack to make javascript behave more like .NET with string.format…


var selector = String.format("#container{0} div.lineItem{1}[data-entryid='{2}']", containerId, itemId, entryId);

js code:

//String.format for js.
if (!String.format) {
String.format = function (format) {
var args =, 1);
return format.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match


Leave a Reply

Your email address will not be published. Required fields are marked *