sprintf is stripping leading zeros from symbols (not ints)
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:
filename - tosymbol - sprintf ?
"01 foo.mp3" is a list with two arguments of type int and symbol ...
yup, there's a tosymbol in the patch already. That's what's so confusing.
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.
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.
In this case, I'd actually just use a pak object and avoid sprintf altogether:
and/or what Chris said :)
-Ben
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)
ah whoops, good catch, lazy patching on my part. A [t b i] and a pack [set 0 i s] would work too:
Wonderful. Thanks to you both. (I have always avoided pack whenever symbols are involved but now I'm enlightened.)