[resolved] sprintf doesn't work with variable number of arguments

My assumption was that if you have more arguments than you have strings-to-substitute in a sprintf, it will just ignore the extra arguments.

e.g. suppose my string is
I have two items, %s and %sbut I pass this to sprintf with three parameters 'one', 'two', and 'three'.

I assumed it would just ignore the 'three', but instead it throws an error:
[Screen Shot 2021-12-27 at 10.10.00 PM.png]
I would also hope it doesn't fail in the other direction, e.g. suppose my string is
I have three items: %s, %s, and %sand I only pass this to sprintf with two parameters 'one' and 'two', I would hope it leaves the last %s in the original string intact.

I currently have a bunch of strings with a variable number of %s's and I know beforehand what each of the parameters will be even if the string doesn't require all of them. It would be nice if this doesn't error out and instead ignores extra/missing parameters.
Other
10 replies