How do I replace one character with something else, in a text - but only the nth occurence...

0 favourites
  • 3 posts
From the Asset Store
Self Typing Text
$0.50 USD
95% off
Change delay, create new lines, "backspace" the text
  • Let's say that I want to replace the second "." that occurs in one string with "!".

    Like thus:


    "This is a house. It has burnt down. How sad."


    "This is a house. It has burnt down! How sad."

    It should be flexible so I can change which of the three "." I want to get replaced at runtime.

    So one time it would replace the first . to !, or another time it would do the last . to !

    I have tried to look up RegexReplace, but I could not find any information on the "flag" part of it. There's no mention about the flags in the manual.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You could utilize tokenat with a loop and “.” As the divider. Then just rebuild the text a token at a time adding the “.” In between. Except when loopindex=2, you can add a “!” Instead.

    Otherwise there may be some regex incantation, but you have to dig into the docs for that.

  • Thank you, I will attempt to do what you suggested. It sounds doable though!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)