Forums > MaxMSP

Substring Function?

July 16, 2007 | 6:44 pm

Is there a way to parse a string in Max? I have some data stored in a coll that I would like to retrieve but I don’t want the string portion of it i.e., "sample16" -> "16". Maybe it’s easier to make another coll with just the int portion?

Thanks,

J



Dan
July 16, 2007 | 10:01 pm

If you add a space between "sample" and "16" when entering the data
in the coll, you can retrieve just the int easily, like so:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 124 124 32 196617 print;
#P message 187 53 42 196617 nth 1 2;
#P message 97 53 65 196617 1 sample 16;
#N coll ;
#P newobj 124 88 53 196617 coll;
#P connect 0 0 3 0;
#P connect 2 0 0 0;
#P connect 1 0 0 0;
#P window clipboard copycount 4;

If, on the other hand, your data isn’t going to have the same form
each time or you just don’t want to bother cleaning it up, you could:

…an embarrassing amount of time later…

I gave it a shot and came up with the bass-ackwards approach below.
Hope it helps. Maybe someone else on the list will be so outraged at
my clumsy kludge that they’ll post an elegant solution. ;)

#P window setfont "Sans Serif" 9.;
#P number 408 315 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 408 291 64 196617 fromsymbol;
#P newex 408 245 55 196617 zl group 2;
#P button 471 47 15 0;
#P newex 381 46 48 196617 loadbang;
#P newex 408 270 108 196617 sprintf symout %s%s;
#P newex 408 168 25 196617 iter;
#P newex 408 193 60 196617 split 48 57;
#P newex 408 143 40 196617 atoi;
#P message 471 72 14 196617 1;
#P message 381 72 62 196617 1 sample16;
#N coll ;
#P newobj 408 107 53 196617 coll;
#P newex 408 220 40 196617 itoa;
#P connect 10 0 7 0;
#P connect 11 0 12 0;
#P connect 7 0 11 0;
#P connect 5 0 0 0;
#P connect 0 0 10 0;
#P connect 2 0 1 0;
#P connect 3 0 1 0;
#P connect 1 0 4 0;
#P connect 6 0 5 0;
#P connect 8 0 2 0;
#P connect 9 0 3 0;
#P connect 4 0 6 0;
#P window clipboard copycount 13;


July 16, 2007 | 10:35 pm

take a look at the regexp object.


July 16, 2007 | 11:53 pm

Imagine that! Thank you.


Viewing 4 posts - 1 through 4 (of 4 total)