Counting Upper and Lower Case Characters?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Counting Upper and Lower Case Characters?
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
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
- Attachments
-
- charactercounter2.jpg (228.53 KiB) Viewed 4565 times
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Counting Upper and Lower Case Characters?
Hi Mike,
Try this
All the best
Jean-Marc
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
Jean-Marc
https://alternatic.ch
Re: Counting Upper and Lower Case Characters?
Hi Mike,
yep, as Jean-Marc already demonstrated, you need to check the ASCII values of the single characters.
Best
Klaus
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?
THANK YOU!
Worked perfectly!
Worked perfectly!
Re: Counting Upper and Lower Case Characters?
Hi,
Have you considered using matchText?
Best,
Mark
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
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- VIP Livecode Opensource Backer
- Posts: 56
- Joined: Sat Apr 08, 2006 5:28 pm
- Location: Eau Claire, WI
- Contact:
Re: Counting Upper and Lower Case Characters?
I like where you're going with the regex, but it doesn't take into account punctuation or other non-letter/numbers.
Ken Ray
Sons of Thunder Software
Email: kray@sonsothunder.com
Web site: http://www.sonsothunder.com
Sons of Thunder Software
Email: kray@sonsothunder.com
Web site: http://www.sonsothunder.com
Re: Counting Upper and Lower Case Characters?
Hi kray,
OP didn't ask for it (yet). The only thing to add is
or
Best,
Mark
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
Code: Select all
set the itemDel to space
put number of items of (myVar & "bla") into myNrOfSpaces
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode