sprintf - padding with trailing spaces?
I cannot figure out how to get right-padding for a string to reach a certain length. For example the string "boa", what do I tell [sprintf] to make it "boa......" –> 9 characters long with trailing spaces?
Here is a way:
i believe sprintf symout %-9s
will do what you want.
Thanks, 'sprintf symout %-9s' does the trick.
'sprintf symout %-9s' does not handle strings with spaces. When I send two words it outputs just one. I don't understand the C++ reference. At least I see no indication that spaces are handled different than other characters.
Is there a solution?
Like most max objects [sprintf] will interpret a list as being sent one item to each inlet. Seeing as you only have one % argument in the [sprintf] object it will have one inlet and only use the first item in the list. The solution is to specify the input as being one symbol, either use quotes in the message box: "my pet". Or use [tosymbol] between the list and [sprintf].
lh
here is another possibility:
like luke said, the problem here isn't sprintf but max. when you think you're sending a string with a space, you're probably sending a list of two strings. if you need to handle strings with whitespace, you'll need to use tosymbol
in some places and quotation marks in others.
actually, this is pretty much exactly what luke said. why did i even write this?
If you don't need extensibility, then sprintf is great, no need to go further.
If you want to be able to change the size of the resulting string, you have to use something else. Here is some fun with the zl family:
@Peter, you can use tosymbol
:
Just another variant:
Wow, there's quite a lot to choose from :-)
Many thanks guys!
Yes, that's why its always fun for me to find yet another way of doing the same...;-)