Advanced string replace()

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

Locked
andy
Posts: 40
Joined: 29 Dec 2014 21:00

Advanced string replace()

Post by andy » 30 Dec 2014 08:39

Hello Martin,
I would like to replace part of string at a given index position. Existing replace() and replaceAll() replaces everything that match search string.
Is there a way to realize something like:

string myreplace(string ori, num startidx, num lenght, string replace)

startidx=position at which one starts to replace
length=number of indices to be replaced

For example:
myreplace("haha", 1, 3,"ello")
It will return "hello"

Regards
Andy

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Advanced string replace()

Post by Martin » 02 Jan 2015 15:19

Hi,

You could use function substring to extract the first and second part:
v = "haha";
t = substring(v, 0, 1) + "ello" + substring(v, 4);

Regards,
Martin

andy
Posts: 40
Joined: 29 Dec 2014 21:00

Re: Advanced string replace()

Post by andy » 02 Jan 2015 15:59

Hi Martin,

Thanx for reply. I was looking for a workaround but I did not notice substring instruction.

I think a combination of replace and substring will give a solution.

Regards

Andy

Locked