I'm not sure of all the implementation details of the original sprintf. I just needed a quick way to print into a string quickly. I also added a shortcut that will detect numeric arguments and optionally pluralize words for you.
so:
"I have %s item(s) but only %s thing(s)".sprintf(3, 1)
1
u/joshuag Jan 28 '12 edited Jan 28 '12
Here's a quick and dirty sprintf implementation that I wrote.
You can have it.
I'm not sure of all the implementation details of the original sprintf. I just needed a quick way to print into a string quickly. I also added a shortcut that will detect numeric arguments and optionally pluralize words for you.
so:
results in the string:
EDIT: I just saw this (http://www.diveintojavascript.com/projects/javascript-sprintf) further down the page. It's a much better, not-so-dirty implementation of sprintf. Use that.