Remove word from a string

Get help using Construct 2

Post » Wed Mar 05, 2014 9:36 pm

Well didn't expect this to be so difficult :)
This doesn't really work

replace(Text.Text, tokenat(Text.Text, 0, " "), "")

If I use replace it removes all the same tokens. So I think I should use RegexReplace.

But I don't quite understand what this means
RegexReplace(String, Regex, Flags, Replace)
In String substitute matches for the regular expression Regex (with Flags) with the string Replace. The replacement string can contain the following special characters: $$ (inserts a $), $& (inserts the matched substring), $` (inserts the portion of the string that precedes the matched substring), or $' (inserts the portion of the string that follows the matched substring).
Last edited by Katala on Thu Mar 06, 2014 8:03 pm, edited 2 times in total.
B
34
S
9
G
3
Posts: 517
Reputation: 5,246

Post » Wed Mar 05, 2014 11:45 pm

This seems to work
Code: Select all
RegexReplace(text.Text , "^\S+\s" , "g" , "")

Still not sure what the flag does though :)
B
34
S
9
G
3
Posts: 517
Reputation: 5,246

Post » Thu Mar 06, 2014 1:25 am

^\S+\s means a line which starts with one or many non white-space character followed by one white-space character (but I think you got that one)
g (global) means you want to replace all the occurence of your regex. Without it would only match the first one.
However in your case, since you're not using the m flag (multi-line), even if your text contains line break, ^ will only consider the begining of the entire string (whith m it considers each line one by one).
So the g flag is useless since you'll only ever have one occurrence matching.

more info over there
B
68
S
22
G
14
Posts: 1,485
Reputation: 16,561

Post » Thu Mar 06, 2014 8:14 pm

Ok remove first word works but how about if I would like to remove word by it's serial number.

I would use this in a RTS build queue variable that could look something like this "1 1 14 24" and this would be handy if the player wants to cancel some units.

I have watched all kinds of guides but cannot seem to wrap my head around it.
B
34
S
9
G
3
Posts: 517
Reputation: 5,246

Post » Sat Mar 08, 2014 7:59 pm

Maybe it would be simpler to use an array rather than writing strings?
B
5
Posts: 12
Reputation: 251

Post » Sat Mar 08, 2014 8:10 pm

@SHOMOFO, Already did just that ;)
B
34
S
9
G
3
Posts: 517
Reputation: 5,246

Post » Sat Mar 08, 2014 8:18 pm

@Katala (^_^)
B
5
Posts: 12
Reputation: 251


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 42 guests