playMaker

Author Topic: [SOLVED]Need to replace within a string...  (Read 1777 times)

kanae

  • Junior Playmaker
  • **
  • Posts: 52
[SOLVED]Need to replace within a string...
« on: November 05, 2014, 08:51:28 AM »
If I have a "12572" string

And I want to replace the first 2 with a 9, how would I do that?  Replacing a string (using a substring) would just replace both 2's, wouldn't it?  So how do I single out that first 2 without modifying the second 2? (I am doing this because I want to use a string like an array via network sync, the string will pass between both players and be updated according to some logic)

I thought of maybe using "build string" out of 3 elements, and doing some int operators to get everything in it's proper place but that seems like such overkill...  But I can't find an action that seems to say "go to char count  _" or "start at index __"... in order to replace within a string
« Last Edit: November 11, 2014, 01:09:52 AM by jeanfabre »

600

  • Beta Group
  • Hero Member
  • *
  • Posts: 713
    • Flashing Lights
Re: Need to replace within a string...
« Reply #1 on: November 06, 2014, 08:36:09 AM »
Hi, Im doing this too for Photon.
It sounds "overkill", but got used to it :)

Get string Left with 1 Char Count,
then substring index 1 (second char),
+ substring start index 2 etc.

save them in different strings as parts and you can change what ever part and build the string back together.

Maybe someone can share a shorter way or a custom action Set Substring?


EDIT:

Ha! its already done, didn't see it before..
Thanks to Jean!

Action:
http://hutonggames.com/playmakerforum/index.php?topic=1912.msg8368#msg8368
« Last Edit: November 06, 2014, 08:39:18 AM by 600 »

kanae

  • Junior Playmaker
  • **
  • Posts: 52
Re: Need to replace within a string...
« Reply #2 on: November 10, 2014, 12:30:02 PM »
hah nice find 600, thanks again :)

I figured it was funny you could get a string index but not replace!