Search for string in array and replace

Get help using Construct 2

Post » Tue Jun 09, 2015 3:58 pm

Is there a way to search for value in array and replace it? I'm guessing I would start with array > contains value, but then how do I replace it?

Example:
Let's say I have an array with dog, cat, bird. Can I find bird and replace it with cow?
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Tue Jun 09, 2015 4:01 pm

You can use "IndexOf" expression to retrieve the index of an element. It works only on the X axis though.
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Tue Jun 09, 2015 4:03 pm

replace() or RegexReplace() are your friends... or maybe estranged fourth cousins.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Tue Jun 09, 2015 7:11 pm

@magistross Do I place the IndexOf in the "Contains value" condition or Compare X? Also, since I am sorting as well and because the list is always changing, I do not know the index number. Does this still apply?
Last edited by jook00 on Tue Jun 09, 2015 9:30 pm, edited 1 time in total.
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Tue Jun 09, 2015 9:19 pm

@gumshow2029 Do I put replace() and RegexReplace() inside the array Insert?
Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582

Post » Wed Jun 10, 2015 12:19 am

Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » Thu Jun 11, 2015 5:06 pm

jook00 wrote:@gumshow2029 Do I put replace() and RegexReplace() inside the array Insert?


You can use it at any place. The main difference between replace() and RegexReplace() is that replace() actually returns a string text for use, while RegexReplace() just overwrites the existing text in the argument.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824


Return to How do I....?

Who is online

Users browsing this forum: StefanSava, zenox98 and 62 guests