Forums > MaxMSP

Replace message at position x to y

March 30, 2013 | 11:57 am

Hi,
I have a message. e.g.:
"I have a nice cat"

Now I want to replace a part of the message from x to y. – e.g: 10-15:
"I have a nice hat"

How can I do that? I can’t find any objects that are related to messages or the string length.

Thanks!


March 30, 2013 | 1:03 pm

Take a look at [regexp], [sprintf] and [combine].


March 30, 2013 | 6:01 pm

Thanks. Are you sure that regexp works? I can only see examples of regexp, where the message structure is known in advance.

I don’t know the structure of the message, because it is more or less random (the user can enter a message). – I only know the position, where I want to replace and how much i want to replace.


March 30, 2013 | 6:13 pm

Got it! – without regex and sprintf :)

– Pasted Max Patch, click to expand. –

March 30, 2013 | 6:19 pm

I’m not an expert with [regexp] and I’m sure there’s a more elegant solution than this one, but here’s a little hack that might do the job using [zl] and [atoi]:

– Pasted Max Patch, click to expand. –

March 30, 2013 | 6:21 pm

I found the solution already and your solution isn’t exactly what I wanted. But thanks! :)


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