How do I check if a textbox contains a word?

Get help using Construct 2

Post » Thu Oct 16, 2014 3:25 am

I can check if the textbox has a specific thing in it like if the text is "dog" I can just check for "dog" and find it, but what if I want to check if it just has "dog" somewhere in it? I need it to detect both "dog" and "the dog jumped high", just whenever "dog" is in the text field, activate. How do I do this?
B
5
S
1
Posts: 59
Reputation: 497

Post » Thu Oct 16, 2014 4:01 am

if find(text, "dog") is > -1 will tell you if "dog" is in the text. Is that what you want?

Check out https://www.scirra.com/manual/126/system-expressions
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Oct 16, 2014 8:16 am

maybe you can loop your words and find if(x == 'd' && x+1 == 'o' && x+2 == 'g') then there's a dog word inside your text.
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
64
S
14
G
2
Posts: 292
Reputation: 6,678

Post » Thu Oct 16, 2014 8:47 am

puntodamar wrote:maybe you can loop your words and find if(x == 'd' && x+1 == 'o' && x+2 == 'g') then there's a dog word inside your text.

Let's keep everything in C2 event system scope/context shall we?

Use codah's suggestion to just check whether "dog" exist.
Use [tokencount("yourText","dog")-1] to check how many occurence "dog" has.
Use event below if you want to check all index (zero-based) of occurence.
Code: Select all
Condition: Repeat tokencount("yourText"," ")
Condition: compare tokenat("yourText",loopindex," ") = "dog"
Action: add <textVariable> with "_"&loopindex


Example, if "yourText" is "the dog the dog the dog the dog the dog"
you should get <textVariable> = _1_3_5_7_9
B
28
S
8
G
4
Posts: 553
Reputation: 4,924


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests