sprintf is stripping leading zeros from symbols (not ints)

    May 20 2010 | 3:22 pm
    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:

    • May 20 2010 | 3:30 pm
      filename - tosymbol - sprintf ?
      "01 foo.mp3" is a list with two arguments of type int and symbol ...
    • May 20 2010 | 4:30 pm
      yup, there's a tosymbol in the patch already. That's what's so confusing.
    • May 20 2010 | 7:08 pm
      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.
    • May 20 2010 | 7:09 pm
      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:
    • May 20 2010 | 7:10 pm
      and/or what Chris said :)
    • May 20 2010 | 7:13 pm
      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)
    • May 20 2010 | 7:29 pm
      ah whoops, good catch, lazy patching on my part. A [t b i] and a pack [set 0 i s] would work too:
    • May 21 2010 | 3:47 am
      Wonderful. Thanks to you both. (I have always avoided pack whenever symbols are involved but now I'm enlightened.)