slicing a big list into smaller lists based on a search string

Feb 20, 2007 at 2:49am

slicing a big list into smaller lists based on a search string

Hi all,
This seems so easy…yet I’ve been scratching my head over this problem all day. Maybe others here have some suggestions before I scratch myself bald.

Let’s say I have a big long message like so:

hippo lion 4 ant 2.3 tiger 0.3 rabbit “happy birthday” 33 0.5

I want to take the big list and break it up into 3 chunks:

hippo lion 4 ant 2.3 tiger 0.3 rabbit “happy birthday” 33 0.5

…based on the appearance of

in the list. I can’t use unpack or iter since I don’t know for certain the length or type of values that will follow . In other 3rd party options I’ve been able to find, seems like you need to know the length of the message you want to generate (e.g. slicelist), or parses in a way that won’t really work for this application (e.g. Lchunk). Any suggestions on how to tackle this?

Thanks,
David

#30357
Feb 20, 2007 at 8:32am

like this? using stock objects only…

/*j

On 20 Feb 2007, at 03:49, David Beaudry wrote:

>
> Hi all,
> This seems so easy…yet I’ve been scratching my head over this
> problem all day. Maybe others here have some suggestions before I
> scratch myself bald.

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 163 251 82 196617 mode group 256;
#P newex 88 309 32 196617 print;
#P newex 88 154 40 196617 t b l b;
#P newex 103 180 47 196617 zl iter 1;
#P newex 118 222 91 196617 route

;
#P window linecount 2;
#P message 88 111 235 196617
hippo lion 4 ant 2.3

tiger 0.3 rabbit “happy birthday” 33 0.5;
#P window linecount 1;
#P newex 88 277 46 196617 zl group;
#P connect 4 2 6 0;
#P connect 6 0 0 0;
#P connect 0 0 5 0;
#P connect 4 0 0 0;
#P connect 3 0 0 0;
#P connect 3 0 2 0;
#P connect 2 0 0 0;
#P connect 4 1 3 0;
#P connect 1 0 4 0;
#P window clipboard copycount 7;
#96910
Feb 20, 2007 at 8:38am

On 20 Feb 2007, at 03:49, David Beaudry wrote:
>
> Let’s say I have a big long message like so:
>
>

hippo lion 4 ant 2.3 tiger 0.3 > rabbit “happy birthday” 33 0.5
>
> I want to take the big list and break it up into 3 chunks:
>
hippo lion 4 ant 2.3
>
tiger 0.3
>
rabbit “happy birthday” 33 0.5
>
> …based on the appearance of
in the list. I can’t use
> unpack or iter since I don’t know for certain the length or type of
> values that will follow
. In other 3rd party options I’ve
> been able to find, seems like you need to know the length of the
> message you want to generate (e.g. slicelist), or parses in a way
> that won’t really work for this application (e.g. Lchunk). Any
> suggestions on how to tackle this?

hi david,
seems a little awkward to do in max, although you could ‘force’
Lchunk to work for your situation (see patch below).
but if you really need this output format, i would probably pull out
some text-based solution.
a simple javascript function could look like this (hopefully the code
turns up correctly):

/********** start script ************/

var keyword = “

“;

function parse() {
var a = arrayfromargs(arguments);
var b = new Array();
for(i=0; i
if( a[i] == keyword ) {
outlet(0, b);
b = new Array();
b.push(keyword);
}
else
b.push(a[i]);
}
outlet(0, b);
}

/*********** end script ************/

hope that helps.
volker

/**** a patch using Lchunk *****/

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 198 113 48 196617 loadbang;
#P newex 34 87 97 196617 append

;
#P newex 34 206 40 196617 print b;
#P newex 34 183 102 196617 prepend
;
#P newex 34 108 80 196617 prepend symbol;
#P newex 34 158 51 196617 zl ecils 1;
#P message 198 135 100 196617 markon
;
#P newex 34 133 40 196617 Lchunk;
#P message 34 45 483 196617
hippo lion 4 ant 2.3

tiger 0.3 rabbit “happy birthday” 33 0.5;
#P connect 8 0 2 0;
#P connect 5 0 6 0;
#P connect 3 0 5 0;
#P connect 1 0 3 0;
#P connect 2 0 1 0;
#P connect 4 0 1 0;
#P connect 0 0 7 0;
#P connect 7 0 4 0;
#P window clipboard copycount 9;
#96911
Feb 20, 2007 at 10:49am

#96912
Feb 20, 2007 at 8:00pm

Hi all,
Thanks for your responses!
I figured the best method was going to lead me to java/javascript…much thanks for the script, Volker!

Best,
David

#96913

You must be logged in to reply to this topic.