Get all combinations of recursive substring replacement
Posted on 2012-08-30
I'm looking for a way to replace a substring within a string, and obtaining all different combinations, for example:
"one leg two legs", and replacing "leg" with "arm" it would return the following strings:
"one leg two legs"
"one arm two legs"
"one leg two arms"
"one arm two arms"
I have made a quite simple routine for this but it fails when replacing "i" with "ie" (infinite recursion because string builds up, pie > piee > pieee > pieeee) and if i fix that by recursing backwards if tails when replacing for example "ch" with "sch" (michael > mischael > misschael > missschael) - im just stuck as hell and trying all night - please help?