PDA

View Full Version : Newbie - Counting A's, B's & C's in a string.


jib
06-15-2007, 03:06 AM
Hey guys,
First off - I'll let you know I haven't had huge amounts of experience with writing code... so hoping someone can guide me slightly here.

My project in summary:
>>>I have a box for input text (lets call it STRINGABC)

>>>I should also have dynamic text on the screen ( lets call A_COUNT), which I would like to automatically count the amount of A's in STRINGABC.

>>>For example, say STRINGABC was "hAppy birthdAy" ... this string contains 2 A's, therefore A_Count should equal 2.

Wondering if anybody knows a simple way to code for this?
Thanks in advance,

_Aerospace_Eng_
06-15-2007, 03:48 AM
You can probably use mystring.toLowerCase().split('a'); this will give you an array of the string. The length of this array should be the number of a's in the string.

Is this an assignment?

jib
06-15-2007, 04:10 AM
Cheers - I'll give that a try.

Does sound like an assignment doesn't it?
It's a project for work... we're a sign-writing company - I am using flash to generate an app, that will help us generate quotes for a new product we are working on.

Wish to anything I could have used excel for this (so much easier!), but wasn't really appropriate for web... and you can only do so much to make it look user friendly.

Thanks again for your help... I'll let you know if it works.

Regards,
Jib

jib
06-15-2007, 05:00 AM
Thanks a lot; with your suggestion - and a bit of experimentation, I figured out I needed to use:

A_Count = StringABC.toLowerCase().split('a').length-1

Very first time using the Actionscript language, so I am very happy it's doing what I want it to.

:thumbsup: Thanks again!