Lets say I have a string "aabbccaa"
. Now I want to replace occurrences of "aa"
in given string by another string. But it should be in following way.
First occurrence of "aa"
should be replaced by "1"
and next occurrence of "aa"
by "2"
and so on.
So, the result of the string becomes "1bbcc2"
.