Replace tokens in text at given index(es)

Get help using Construct 2

Post » Tue Aug 07, 2012 9:55 am

Hello guys,

There's an action "replace" for the text. Currently it replaces all occurrences of a given token in a string. Is it possible to limit it to a token index or a range of indexes (e.g. replace "B" with "X" at 6-12).

The only workaround I can think of is converting this string to an array, than replacing characters in the array and converting it back to text.   
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Tue Aug 07, 2012 11:20 am

I found another work around.

You can combine following string operations:

Set value: left("String",4) & replace(mid("String",5,4)) & right("String",5)

Basically "right" and "left" copies characters from the end an beginning of the string and replace "mid" inserts new characters. xoros2012-08-07 12:47:22
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Tue Aug 07, 2012 2:42 pm

Are you sure you don't just want to use an array of strings? It sounds like it'd be easier than doing a lot of string manipulation.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,574

Post » Tue Aug 07, 2012 4:40 pm

I think, I have a tendency to over-complicate "the code", but in this case it just works fine and saves extra steps of creating an array, pushing values into it (it's a string from XML file).xoros2012-08-07 16:54:29
B
42
S
11
G
4
Posts: 505
Reputation: 7,267


Return to How do I....?

Who is online

Users browsing this forum: gregorysforster, heliogame, WhosWho and 16 guests