Replacing text, 1 and not 10...

0 favourites
  • 4 posts
From the Asset Store
Creepy Sprite Font suitable font for your Dark/Horror/Halloween games.
  • Wasn't really sure how to word this in the subject, but basically here is my situation and I'm trying to figure out a work around without doing tons of steps :).

    I have a string for example tmpString = "1,2,3,4,5,6,7,10,11,12,21,101,102,202,1001"

    I want to remove the 1 from the string so I would use

    replace(tmpString, "1", "")

    This would result in the string now being (all the 1's are gone)


    if I replace "1," The 101, would get changed to 10

    Same thing will happy when I want to replace 2. Etc.

    I hope that makes sense. Curious if anyone has a trick up their sleeve for this. I though about making it "01,02,03" But the string is being built from array and loop indexes.

    I'm not too familiar with Regex, so maybe there is something there I can use?


  • Seems like I always fix my issues after I post haha.

    I was able to use RegExReplace just "" for no flag. So it finds the first on the the string, which is exactly what I needed.

    In case someone comes across this questions at some point.

    RegexReplace (tmpString, "1", "", "") is what I used.

  • I usually add extra commas at start and end of the string. So it looks like this:


    This way I can replace ",1," with "," and it will not ruin other numbers.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yeah, I am in a unique situation where that wouldn't work for me. I need to use Tokencount and the extra commas throw off the count. It's odd, but thanks for the tip!

    I could probably just subtract the amount based on the extra commas, but anyway. I got it working lol.

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