Page 1 of 1

Advanced string replace()

Posted: 30 Dec 2014 08:39
by andy
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

Re: Advanced string replace()

Posted: 02 Jan 2015 15:19
by Martin
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

Re: Advanced string replace()

Posted: 02 Jan 2015 15:59
by andy
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