What is the practical difference between sprintf and $s in message?

Masa's icon

In other words, what is the advantage of using sprintf instead of $s in message?

Many thanks for your help,
Masa

hz37's icon
Max Patch
Copy patch and select New From Clipboard in Max.

sprintf is known and loved by programmers who come from a c/c++/php background. It also has some convenient formatting options.

Jan M's icon

There is also a conceptual difference between the two: the $x ($1 to $9) are changeable arguments within a message. They are intended to create (max) lists with changing elements inside, but not to change the format of the output. What goes in will come out. The output will be a list, therefore there will be always a white space between the inserted value and the rest of the list.
[sprintf] is basically an expose c function which is meant to format strings (a string in other programming languages is what is called a "symbol" within max). As HZ37 said it is a very versatile tool.

Max Patch
Copy patch and select New From Clipboard in Max.

Here are some more examples how sprintf and Max can work together:

Masa's icon

Thank you very much HZ37.

Thanks a lot again Jan, the example patch is really helpful to understand how they work differently.