If you look at MDC there's no method named Format
for the String
object. My guess is that you are confusing languages (JavaScript and C#), which is quite common for multi-language developers.
However, everything's not lost. You can easily recreate an equivalent method in JavaScript by adding to the prototype of the String
object. Credits go to gpvos, Josh Stodola, infinity and Julian Jelfs who contributed to these solutions to a similar problem.
String.prototype.format = function(){
var args = arguments;
return this.replace(/\{(\d+)\}/g, function (m, n) { return args[n]; });
};
With a little tweaking it should work like this:
$("span.resource").each(function(){
if (this.id == "l1") {
var $this = $(this),
newText = $this.text().format(var1, var2);
$this.text(newText);
}
});
Blair Mitchelmore have a similar implementation on his blog, but with some extra features and added functionality. You might want to check that out as well!