Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: kanae on November 05, 2014, 08:51:28 AM

Title: [SOLVED]Need to replace within a string...
Post by: kanae 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
Title: Re: Need to replace within a string...
Post by: 600 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
Title: Re: Need to replace within a string...
Post by: kanae 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!