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?
B
60
S
19
G
3
Posts: 451
Reputation: 6,364

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
75
S
31
G
27
Posts: 1,012
Reputation: 20,759

Post » Tue Jun 09, 2015 4:03 pm

replace() or RegexReplace() are your friends... or maybe estranged fourth cousins.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"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
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

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.
B
60
S
19
G
3
Posts: 451
Reputation: 6,364

Post » Tue Jun 09, 2015 9:19 pm

@gumshow2029 Do I put replace() and RegexReplace() inside the array Insert?
B
60
S
19
G
3
Posts: 451
Reputation: 6,364

Post » Wed Jun 10, 2015 12:19 am

B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

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
I don't check the forums much anymore, but I will receive an email for PMs.

"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
23
S
6
G
1
Posts: 1,419
Reputation: 4,857


Return to How do I....?

Who is online

Users browsing this forum: dop2000, Maako and 5 guests