Skip to main content
13-Aquamarine
March 8, 2026
已解决

Replace a string with a string

  • March 8, 2026
  • 1回复
  • 270查看

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

最佳答案由 Werner_E

You may try this string replace function.

grafik.png

1回复

Werner_E25-Diamond I回答
25-Diamond I
March 8, 2026

You may try this string replace function.

grafik.png

13-Aquamarine
March 9, 2026

Thank You!  I learn so much from this forum!  Your suggestion works!

14-Alexandrite
March 9, 2026

@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.

 

Screenshot 2026-03-09 082605.png
 
If you want the flexibility an exhaustive search while having the protection from recursion, then combine both function so that you keep track of the position only if there can be a recursion:
 
Screenshot 2026-03-09 083310.png

"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.