using sprintf with a comma


    Nov 16 2006 | 8:26 pm
    Hello, I have a basic question about sprintf. I have a patch where I'm
    sending a message to the 'forward' object that tells the object what receive
    to send to and what to actually send. I want to use sprintf to do that but
    the forward object requires a comma in its message and sprintf gets weird
    with commas. My patch is below. Any advice?
    max v2;

    • Nov 16 2006 | 9:10 pm
      if u look closely at the text of your patch mode you will find your answer :
      >
      put a backslash before your comma,
      best
    • Nov 17 2006 | 11:29 am
      On 16 nov. 06, at 21:26, Nic Zwart wrote:
      > Hello, I have a basic question about sprintf. I have a patch where
      > I'm sending a message to the 'forward' object that tells the object
      > what receive to send to and what to actually send. I want to use
      > sprintf to do that but the forward object requires a comma in its
      > message and sprintf gets weird with commas. My patch is below.
      > Any advice?
      Hi,
      It's a common misunderstanding. The comma have a special behavior of
      the message box object, where it is used to separate elements. So if
      you really want the "normal comma" character you need to put a
      backslash.
      I would prefer the version without the message boxes (avoiding UI
      objects is always fine, when you don't need the UI aspect).
      Best,
      ej
    • Nov 17 2006 | 8:50 pm
      Great! thanks for your help.
      nic
      On 11/17/06, Emmanuel Jourdan wrote:
      >
      > On 16 nov. 06, at 21:26, Nic Zwart wrote:
      >
      > > Hello, I have a basic question about sprintf. I have a patch where
      > > I'm sending a message to the 'forward' object that tells the object
      > > what receive to send to and what to actually send. I want to use
      > > sprintf to do that but the forward object requires a comma in its
      > > message and sprintf gets weird with commas. My patch is below.
      > > Any advice?
      >
      > Hi,
      >
      > It's a common misunderstanding. The comma have a special behavior of
      > the message box object, where it is used to separate elements. So if
      > you really want the "normal comma" character you need to put a
      > backslash.
      >
      > I would prefer the version without the message boxes (avoiding UI
      > objects is always fine, when you don't need the UI aspect).
      >
      > Best,
      > ej
      >
      > #P window setfont "Sans Serif" 9.;
      > #P window linecount 2;
      > #P message 860 165 74 196617 ; duck 9;
      > #P window linecount 1;
      > #P newex 860 135 30 196617 t b s;
      > #P number 981 63 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
      > #P message 860 65 30 196617 duck;
      > #P newex 860 100 131 196617 sprintf set \; %s %ld;
      > #P comment 842 43 260 196617 why not using the send feature of the
      > message box?;
      > #P message 110 65 30 196617 duck;
      > #P newex 110 176 68 196617 prepend send;
      > #P number 68 64 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
      > #P newex 68 215 65 196617 forward duk;
      > #P comment 212 34 260 196617 change the contents of the message box
      > , and trigger it !;
      > #P newex 583 195 47 196617 forward;
      > #P message 583 165 74 196617 send duck , 8;
      > #P newex 583 135 30 196617 t b s;
      > #P number 704 63 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
      > #P message 583 65 30 196617 duck;
      > #P newex 583 100 131 196617 sprintf set send %s \, %ld;
      > #P newex 354 177 68 196617 prepend send;
      > #P newex 267 152 97 196617 unpack 0 s;
      > #P newex 267 126 97 196617 zl rot 1;
      > #P number 354 63 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
      > #P message 267 65 30 196617 duck;
      > #P number 139 317 290 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
      > #P newex 139 294 67 196617 receive duck;
      > #P newex 267 100 97 196617 pack s 0;
      > #P newex 267 216 47 196617 forward;
      > #P comment 538 43 260 196617 change the contents of the message box
      > , and trigger it !;
      > #P connect 23 0 22 0;
      > #P connect 24 0 22 1;
      > #P connect 22 0 25 0;
      > #P connect 25 1 26 0;
      > #P connect 25 0 26 0;
      > #P connect 5 0 2 0;
      > #P connect 6 0 2 1;
      > #P connect 3 0 4 0;
      > #P connect 2 0 7 0;
      > #P connect 7 0 8 0;
      > #P connect 8 1 9 0;
      > #P connect 8 0 1 0;
      > #P connect 9 0 1 0;
      > #P connect 11 0 10 0;
      > #P connect 12 0 10 1;
      > #P connect 10 0 13 0;
      > #P connect 13 0 14 0;
      > #P connect 13 1 14 0;
      > #P connect 14 0 15 0;
      > #P connect 20 0 19 0;
      > #P connect 19 0 17 0;
      > #P connect 18 0 17 0;
      > #P window clipboard copycount 27;
      >
      >