Page 1 of 1

Counting Upper and Lower Case Characters?

Posted: Wed Jan 19, 2011 2:14 pm
by mikesign
This works on the first field but can't seem to find the upper and lower or space functions?
I want to be able to return just the number of UPPER case characters and LOWER case characters?

on mouseUp --Compute Button
put the number of chars of field "userInput" into field "numCharField"
put the number of UPPERCHARACTERS of field "userInput" into field "upCharField"
put the number of LOWERCHARACTERS of field "userInput" into field "loCharField"
put the number of SPACES of field "userInput" into field "numSpaceField"
end mouseUp

I think i might be able to do this with an Item Delimiter? Any Thoughts?
Thank You Mike

Re: Counting Upper and Lower Case Characters?

Posted: Wed Jan 19, 2011 2:56 pm
by jmburnod
Hi Mike,
Try this

Code: Select all

on UpLowAndSpace --Compute Button
   put fld "userInput" into tText
   put the number of chars of tText into NbChar
   put 0 into tUp
   put 0 into tLow
   put 0 into tspace
   repeat for each char MyChar in tText
      put chartonum(myChar) into MyCTN
      if myCTN = 32 then add 1 to tspace
      if myCTN > 64 and myCTN < 97 then add 1 to tUp --•• from A to Z or what you want
      if myCTN > 96 and myCTN < 123 then add 1 to tlow --•• from a to z or what you want
   end repeat
   put NbChar into field "numCharField"
   put tUp into field "upCharField"
   put tlow into field "loCharField"
   put tspace into field "numSpaceField"
end UpLowAndSpace 
All the best

Jean-Marc

Re: Counting Upper and Lower Case Characters?

Posted: Wed Jan 19, 2011 5:46 pm
by Klaus
Hi Mike,

yep, as Jean-Marc already demonstrated, you need to check the ASCII values of the single characters.


Best

Klaus

Re: Counting Upper and Lower Case Characters?

Posted: Wed Jan 19, 2011 9:40 pm
by mikesign
THANK YOU!
Worked perfectly! :D

Re: Counting Upper and Lower Case Characters?

Posted: Sat Jan 22, 2011 3:06 am
by Mark
Hi,

Have you considered using matchText?

Code: Select all

put number of chars of replaceText("ThiSisText7withUpperAndLowerCASE","[a-z0-9]","") into myUpperChars
put number of chars of replaceText("ThiSisText7withUpperAndLowerCASE","[A-Z0-9]","") into myLowerChars
put number of chars of replaceText("ThiSisText7withUpperAndLowerCASE","[a-zA-Z]","") into myNumbers
Best,

Mark

Re: Counting Upper and Lower Case Characters?

Posted: Sat Jan 22, 2011 9:17 am
by kray
I like where you're going with the regex, but it doesn't take into account punctuation or other non-letter/numbers.

Re: Counting Upper and Lower Case Characters?

Posted: Sat Jan 22, 2011 12:19 pm
by Mark
Hi kray,

OP didn't ask for it (yet). The only thing to add is

Code: Select all

put number of chars of replaceText("ThiSisText7withUpperAndLowerCASE","[ ]","") into myNrOfSpaces //0
or

Code: Select all

set the itemDel to space
put number of items of (myVar & "bla") into myNrOfSpaces
Best,

Mark