Replace message at position x to y

Mar 30, 2013 at 11:57am

Replace message at position x to y

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!

#67431
Mar 30, 2013 at 1:03pm

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

#242586
Mar 30, 2013 at 6:01pm

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.

#242587
Mar 30, 2013 at 6:13pm

Got it! – without regex and sprintf :)

– Pasted Max Patch, click to expand. –
#242588
Mar 30, 2013 at 6:19pm

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. –
#242589
Mar 30, 2013 at 6:21pm

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

#242590

You must be logged in to reply to this topic.