The PTC Community is on temporary read only status in preparation for moving our community to a new platform. Learn more here
I have a character replace function. I would like to use it to replace a string with a string. If the user inputted duplicate "OR's" then I want the function to thin out "OR OR" to just "OR".
Thanks in advance
Solved! Go to Solution.
Thank You! I learn so much from this forum! Your suggestion works!
@Snowshoeman just do an initial search for "s1" inside "s2". If it is, then return the original text so that you do not have an infinite recursion. Or, like typical replace functions, keep track of the position of the last search and so that the replacement text does not itself get searched. Here are both examples.
"check" remembers if "s1" is inside "s2", then in the 'if' function, "pos" is advanced if "check" is true, or it is reset to zero if not.
Thanks!
@SPaulis wrote:
@Snowshoeman just do an initial search for "s1" inside "s2". If it is, then return the original text so that you do not have an infinite recursion.
Actually my suggestion did not use recursion but rather an iteration loop.
But I like the idea of intercepting the infinite loop that could occur in some cases.
And since we were just talking about recursion, here is a recursive variant of the string replacement that solves the problem in a similar way.
Thanks! I will chew on this too.
