string comparison?

Jun 10, 2008 at 3:44pm

string comparison?

#38321
Jun 10, 2008 at 4:03pm

#133386
Jun 10, 2008 at 4:17pm

#133387
Jun 10, 2008 at 4:42pm

On Jun 10, 2008, at 8:44 AM, Diemo Schwarz wrote:

> it should be obvious, but I didn’t find a way to test two non-
> constant symbols for equality in max!?

The Jasch objects contain many string operators including strcmp.

http://www.jasch.ch/dl/default.htm

-C

Chris Muir
cbm@well.com

http://www.xfade.com

#133388
Jun 11, 2008 at 4:55am

a hack way could be with atoi, then find a way to compare the numerical values. Would be simple if they are single characters, trickier if they are words (so become lists of #s). These might be easier to work with using match (?) not sure. At least they’re then numbers.

mxj likely has plenty to do this, if you want to do a little Java. But that seems like extra effort when there are those other options as mentioned here—jasch has tons of stuff for strings, not to mention a lot of other very useful objects.

–CJ

#133389
Jun 11, 2008 at 12:38pm

I use atoi in a few special cases, like checking an index number at the end of a string. But otherwise, i use jasch’s strcmp. It’s fine, only thing i’d like it to have is a right inlet.

atoi -> zl ecils 4 -> itoa -> strcmp for extension comparison.

#133390
Jun 11, 2008 at 2:50pm

Diemo Schwarz schrieb:
> it should be obvious, but I didn’t find a way to test two non-constant
> symbols for equality in max!?

I had a St.change abhaXion based on match for a long time in my St.ools
collection, but found a better way in the mean time:
(There is a “===” and a “St.Change” embedded which could be saved
seperately…)

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#N vpatcher 20 74 620 474;
#P window setfont “Sans Serif” 9.;
#P window linecount 0;
#N vpatcher 20 74 620 474;
#P window setfont “Sans Serif” 9.;
#P newex 67 183 44 196617 sel 1 0;
#P newex 139 74 51 196617 prepend 0;
#P newex 50 74 51 196617 prepend 0;
#P newex 50 160 45 196617 &&;
#P newex 50 95 80 196617 t l l 0;
#P newex 67 50 70 196617 patcherargs;
#P newex 139 118 34 196617 zl len;
#P newex 50 139 99 196617 ==;
#P newex 50 118 34 196617 zl len;
#P newex 85 118 53 196617 zl sub;
#P inlet 50 54 15 0;
#P inlet 139 54 15 0;
#P outlet 67 205 15 0;
#P outlet 50 182 15 0;
#P connect 3 0 11 0;
#P connect 11 0 9 0;
#P connect 9 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 10 0;
#P connect 10 0 0 0;
#P fasten 10 0 13 0 55 180 72 180;
#P connect 13 0 1 0;
#P connect 9 1 4 0;
#P connect 4 0 10 1;
#P connect 9 2 10 1;
#P fasten 12 0 4 1 144 95 133 95;
#P fasten 8 0 12 0 72 70 144 70;
#P connect 2 0 12 0;
#P connect 12 0 7 0;
#P connect 7 0 6 1;
#P pop;
#P newobj 76 77 72 196617 p ===;
#P window linecount 1;
#P newex 76 109 26 196617 + 1;
#P newex 76 131 45 196617 gate 2 1;
#N vpatcher 10 59 229 306;
#P outlet 61 187 15 0;
#P outlet 145 187 15 0;
#P outlet 99 187 15 0;
#P inlet 99 73 15 0;
#P connect 0 0 3 0;
#P connect 0 0 1 0;
#P connect 0 0 2 0;
#P pop;
#P newobj 50 50 36 196617 p t;
#P inlet 50 30 15 0;
#P outlet 76 153 15 0;
#P outlet 111 153 15 0;
#P outlet 138 153 15 0;
#P connect 3 0 4 0;
#P connect 4 2 7 0;
#P connect 7 0 6 0;
#P connect 6 0 5 0;
#P connect 5 0 2 0;
#P fasten 4 0 5 1 55 101 116 101;
#P connect 5 1 1 0;
#P fasten 4 1 7 1 68 72 143 72;
#P connect 7 1 0 0;
#P pop;
#P newobj 56 66 105 196617 p St.change;
#P number 18 66 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 18 38 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 150 86 15 0;
#P newex 103 104 57 196617 print same;
#P window linecount 2;
#P newex 56 104 46 196617 print different;
#P window linecount 1;
#P message 173 36 51 196617 different;
#P message 134 36 34 196617 other;
#P message 95 36 34 196617 same;
#P window linecount 2;
#P message 56 25 34 196617 same again;
#P window linecount 6;
#P comment 169 57 132 196617 Change object for more than just integers.
Middle outlet will route the input on no change and right output bangs
on no change. Right inlet sets without output.;
#P connect 4 0 10 0;
#P connect 3 0 10 0;
#P connect 2 0 10 0;
#P connect 9 0 10 0;
#P connect 8 0 10 0;
#P connect 1 0 10 0;
#P connect 10 0 5 0;
#P connect 10 1 6 0;
#P connect 10 2 7 0;
#P window clipboard copycount 11;


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#133391
Jun 11, 2008 at 3:24pm

Cool solution, St!
Can’t be arsed to build it into my patch in various places, but I like avoiding externals when possible, so I could use this in the future…

#133392
Dec 30, 2008 at 5:57pm

Hi Stefan

Need to do the same thing but I can’t see how this works. I expected to see two inlets for the two strings but there is only one. Could you leave a line or two explaining how this works?

Thanks in advance.

a+
gar

#133393
Dec 30, 2008 at 6:47pm

Here are two versions that compare symbols in max 4. One is similar to [change] and the other to [==]. I hope they help.

lh

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 352 68 31 196617 a b c;
#P message 321 68 24 196617 bye;
#P message 299 68 16 196617 hi;
#N vpatcher 20 74 369 343;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 121 69 31 196617 t s s;
#P newex 61 151 70 196617 gate 2;
#P newex 166 129 72 196617 expr 1-$i1+1;
#P newex 166 109 96 196617 t i i;
#P newex 142 89 34 196617 zl sub;
#P inlet 121 51 15 0;
#P inlet 166 71 15 0;
#P outlet 252 129 15 0;
#P outlet 61 171 15 0;
#P outlet 121 171 15 0;
#P fasten 7 0 8 0 171 148 66 148;
#P connect 8 0 1 0;
#P connect 4 0 9 0;
#P connect 9 0 8 1;
#P connect 8 1 0 0;
#P connect 9 1 5 0;
#P connect 3 0 5 1;
#P connect 5 1 6 0;
#P connect 6 0 7 0;
#P connect 6 1 2 0;
#P pop;
#P newobj 195 93 114 196617 p;
#N vpatcher 20 74 384 348;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 126 56 40 196617 t s s s;
#P newex 66 143 70 196617 gate 2;
#P newex 165 121 72 196617 expr 1-$i1+1;
#P newex 165 101 96 196617 t i i;
#P newex 141 81 34 196617 zl sub;
#P inlet 126 38 15 0;
#P outlet 126 163 15 0;
#P outlet 66 163 15 0;
#P outlet 251 121 15 0;
#P fasten 6 0 7 0 170 140 71 140;
#P connect 7 0 1 0;
#P connect 3 0 8 0;
#P connect 8 0 7 1;
#P connect 7 1 2 0;
#P fasten 8 2 4 0 161 78 146 78;
#P fasten 8 1 4 1 146 75 170 75;
#P connect 4 1 5 0;
#P connect 5 0 6 0;
#P connect 5 1 0 0;
#P pop;
#P newobj 54 93 113 196617 p;
#P message 248 68 31 196617 a b c;
#P message 217 68 24 196617 bye;
#P message 195 68 16 196617 hi;
#P newex 247 113 44 196617 print !=;
#P newex 194 113 47 196617 print ==;
#P toggle 299 113 15 0;
#P message 140 68 31 196617 a b c;
#P message 111 68 21 196617 pie;
#P message 79 68 24 196617 bye;
#P message 54 68 16 196617 hi;
#P newex 105 113 44 196617 print !=;
#P newex 54 113 47 196617 print ==;
#P toggle 156 113 15 0;
#P connect 17 0 14 1;
#P connect 16 0 14 1;
#P connect 15 0 14 1;
#P connect 14 1 9 0;
#P connect 14 0 8 0;
#P connect 10 0 14 0;
#P connect 11 0 14 0;
#P connect 12 0 14 0;
#P connect 14 2 7 0;
#P connect 13 1 2 0;
#P connect 13 0 1 0;
#P connect 3 0 13 0;
#P connect 4 0 13 0;
#P connect 5 0 13 0;
#P connect 6 0 13 0;
#P connect 13 2 0 0;
#P window clipboard copycount 18;

#133394
Jan 3, 2009 at 6:10pm

Hi thereishopeforus@hotmail.com

Thanks for this, works well, got sidetracked for a few days, sorry for being slow to respond.

a+
gar

#133395
Jan 3, 2009 at 6:55pm

there is also the jit.str.op object which has some interesting features ( if jitter is an option )

– Pasted Max Patch, click to expand. –

Quote: Diemo Schwarz wrote on Tue, 10 June 2008 17:44
—————————————————-
>
> Hi,
>
> it should be obvious, but I didn’t find a way to test two non-constant symbols
> for equality in max!?
>
> � [==] only works on numbers
> � [route] only compares a symbol with a fixed symbol
> � [select] loses its second inlet to set the comparand as soon as you put a
> symbol in its args
> � the help of the [if] object mentions $s1, but then tells me: bad expression
> $s1 == $s2
>
> what I actually want is a [change] object for symbols…
>
> I’d be grateful for any hints. Cheers…
> …Diemo
>
>
> —
> Diemo Schwarz, PhD — http://diemo.concatenative.net
> Real-Time Music Interaction Team — http://imtr.ircam.fr
> IRCAM – Centre Pompidou — 1, place Igor-Stravinsky, 75004 Paris, France
> Phone +33-1-4478-4879 — Fax +33-1-4478-1540
>
—————————————————-

#133396
Jan 9, 2009 at 9:08am

#133397

You must be logged in to reply to this topic.