Counting specific letters in words

Get help using Construct 2

Post » Fri Jul 12, 2013 12:46 am

If I wanted to use a textbox with a word in it, or say a global variable storing that word, how would I go about counting for example all the "A"s in the word? Is that even possible? I can count the letters sure, using len(Word.Text), but I want to count specific letters. Is there a way to achieve this?
B
17
S
3
Posts: 225
Reputation: 2,358

Post » Fri Jul 12, 2013 1:21 am

You can loop through each letter in the textbox, check if it's a certain letter, and if so, add 1 to a local variable. I'm not at my main PC, so I can't upload a capx, but it would be something like:

Local varaible "A Count" = 0

Repeat (len(textbox.text))
    {
    If lowercase(mid(textbox.text,loopindex,1)) = "a"
        {
        add 1 to local variable "A Count"
        }
     }

If you're still having difficulty, let me know and I'll upload a capx when I get a chance.zatyka2013-07-12 01:24:03
B
55
S
17
G
8
Posts: 339
Reputation: 11,736

Post » Fri Jul 12, 2013 1:25 am

oh dude awesome. That's a very ingenious way to make it work!
B
17
S
3
Posts: 225
Reputation: 2,358

Post » Fri Jul 12, 2013 2:12 am

Also you can totally upload a capx so I can see it in greater detail. I'm trying to make it work myself, but I'd like to see how you did it.
B
17
S
3
Posts: 225
Reputation: 2,358

Post » Fri Jul 12, 2013 3:05 am

B
55
S
17
G
8
Posts: 339
Reputation: 11,736

Post » Fri Jul 12, 2013 4:29 am

Actually I got it working, but thanks a lot!
B
17
S
3
Posts: 225
Reputation: 2,358


Return to How do I....?

Who is online

Users browsing this forum: BobOfAMillion, jhjconstruct, MAVERICK, tarek2 and 10 guests