sprintf is stripping leading zeros from symbols (not ints)

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

I know how to tell sprintf to pad an int with leading zeros, but this problem is different: I'm trying to fill a jit.cellblock with filenames, but the names often begin with numbers. I'm using sprintf to generate a message likeset 0 1 filename
The filename might actually be "01 Foo.mp3" and sprintf insists on changing that to
"1 Foo.mp3". How do I stop it? Simple test patch below:

Roman Thilenius's icon

filename - tosymbol - sprintf ?

"01 foo.mp3" is a list with two arguments of type int and symbol ...

zlp's icon

yup, there's a tosymbol in the patch already. That's what's so confusing.

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

The problem is that sprintf is making a list to send to cellblock, and leading zeros are not accepted in a list. You can't use symout in sprintf because then jit.cellblock won't understand it. Here's a sprintf-free solution.

Ben Bracken's icon

the output of sprintf will be a list of symbols and numbers, so that number becomes a number again. You can use the symout attribute to output the whole deal as a symbol, but in your then you would have to prepend the rest of the string contents to get it to do what you want it to do, which is a hassle and probably not that efficient.

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

In this case, I'd actually just use a pak object and avoid sprintf altogether:

Ben Bracken's icon

and/or what Chris said :)

-Ben

Chris Muir's icon

Similar solutions, seconds apart. The problem with the pak solution is that it will redundantly set the cellblock cell. (I'm on an efficiency kick lately, trying to wring the last bit of performance out of my aging MacBook Pro)

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

ah whoops, good catch, lazy patching on my part. A [t b i] and a pack [set 0 i s] would work too:

zlp's icon

Wonderful. Thanks to you both. (I have always avoided pack whenever symbols are involved but now I'm enlightened.)