View the Project on GitHub MArcJ/mootools-sprintf

+ Test/Demo page

Javascript sprintf for mootools

This is just a small function, that provides almost the same as php's sprintf.

Take a look at the docu of php's sprintf to get more informationen about the possibilities.


console.log("Hi %s, you have %d new messages!".sprintf('Peter', 3)); //Hi Peter, you have 3 new messages!

var text = "My name is %s and I'm %s, because I'm %1$s".;
console.log(text.sprintf('Peter', 'holy')); //My name is Peter and I'm holy, because I'm Peter

Possible types:

Text Copyright by

Argument swapping

This function supports argument swapping, which means, you can use a argument as many as you want in the text. Just use for example following to output the first argument as string again.

"Si, glamour is %s, or is it not %1$s?".sprintf('useless');

More information

Please take a look at this page: to get more information about the possibilities.