Does $ need a space in front?

Oct 24, 2007 at 4:11am

Does $ need a space in front?

I’m trying to use a variable to tell a buffer to read different audio files and so I’m using the following configuration to change a file’s name for the buffer.

max v2;
#N vpatcher 10 59 610 459;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 95 32 14 196617 3;
#P message 67 32 14 196617 2;
#P message 41 32 14 196617 1;
#P button 50 93 15 0;
#P newex 50 115 43 196617 delay 1;
#P message 50 142 72 196617 read file 3.aif;
#P message 50 64 95 196617 set read file $1.aif;
#P newex 50 170 67 196617 buffer~ files;
#P connect 7 0 1 0;
#P connect 6 0 1 0;
#P connect 5 0 1 0;
#P connect 1 0 4 0;
#P connect 4 0 3 0;
#P fasten 1 0 2 0 55 85 32 85 32 137 55 137;
#P connect 3 0 2 0;
#P connect 2 0 0 0;
#P pop;

My question—

Is it not possible to use $1 without a space in front of $-sign? When I use the text string [set read file$1.aif] it doesn’t work, but [set read file $1.aif] works just fine. Yeah, I know I can just name all my files as “file 1.aif,” “file 2.aif,” but I’d really prefer to not have a space in the file name. Thanks.

#34295
Oct 24, 2007 at 4:18am

On 24 oct. 07, at 06:11, Brian Shepard wrote:

> My question—
>
> Is it not possible to use $1 without a space in front of $-sign?
> When I use the text string [set read file$1.aif] it doesn’t work,
> but [set read file $1.aif] works just fine. Yeah, I know I can
> just name all my files as “file 1.aif,” “file 2.aif,” but I’d
> really prefer to not have a space in the file name. Thanks.

Right, $n needs a space before. For string concatenation, have a look
to the sprintf object: [sprintf symout file %d.aif] should do what
you need.

HTH,
ej

#115456
Oct 24, 2007 at 5:50pm

ej,

Thanks for the tip on sprintf. I was afraid that would be the case. I may just opt for the space in the file name rather than the extra processing of sprintf since this will be a pretty processor-intensive patch when it’s done.

#115457
Oct 24, 2007 at 9:16pm

On 24 oct. 07, at 19:50, Brian Shepard wrote:

> ej,
>
> Thanks for the tip on sprintf. I was afraid that would be the
> case. I may just opt for the space in the file name rather than
> the extra processing of sprintf since this will be a pretty
> processor-intensive patch when it’s done.

I’ve never seen any problem of performance with sprintf. I wouldn’t
worry too much about the overhead.

ej

#115458
Oct 25, 2007 at 1:44am

You’re right, sprintf works great! Thanks for the tip.

#115459

You must be logged in to reply to this topic.