Replace text in a string

Get help using Construct 2

Post » Tue Oct 09, 2012 4:47 pm

Is it possible to search for more than one bit of text to replace in a string.

For example

replace("This*and This%", ('*', '%'), " ")

... Obviously the above doesn't work :s
I can't think of any efficient alternatives...

Maybe

replace(replace("This*and This%", "*", " ")), "%", " ")
This works ^^ But just doesn't seem right. Maybe I'm just being anal

Thanks in advanced!
B
12
S
2
Posts: 39
Reputation: 1,069

Post » Tue Oct 09, 2012 4:56 pm

String is a set of caracters, i don't think it's needed to use * and %, are for math functions.

Perhaps you should use & which can connect between the strings
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,646

Post » Tue Oct 09, 2012 5:14 pm

Sorry, this was just an example! It's actually for a music program...

Here is a better example:
replace("A2,A3,A4", ('2', '3', '4'), "A5")
(Best example I could come up with right now)
B
12
S
2
Posts: 39
Reputation: 1,069

Post » Tue Oct 09, 2012 5:47 pm

The second way you mentioned is the way to do it, you can only replace one string at a time.
B
79
S
24
G
55
Posts: 4,755
Reputation: 41,273

Post » Tue Oct 09, 2012 6:20 pm

Thanks mate! It actually makes a lot of sense now that I got my head around it.

Cheers guys.
B
12
S
2
Posts: 39
Reputation: 1,069

Post » Sat Jan 19, 2013 11:23 pm

@ Joannesalfa
Thanks for that comment "use &" it solved my problem as well for using things like "Stone:"&Mountain.Stone :)
B
7
Posts: 10
Reputation: 1,046


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, selaus and 0 guests