Check percentage of uppercase letters?

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Steven F

Member
Apr 9, 2017
10
0
0
25
Hi,

I am trying to make a chat control type of Skript, and one of the things I want to do is anti-caps.

Would there be a way to check if a chat message contains 80% capitalized letters if over X length for example?

I know you can get the length, just unsure about the caps percentage.

Thanks! :emoji_slight_smile:
 
Last edited:
This is just assuming the following effect is syntactically correct
code_language.skript:
 set {_split::*} to message split at ""

Which would return a list variable with all characters in a message, and that comparing "A" with "a" would return that they're not equal.

Use that effect and then loop the variable, see if the letter is an uppercased letter and if it is, add 1 to a counter variable. Divide it by the size of the message and if the result is higher than 0.8, cancel the event.

Those are such specific cases that I have no clue if they work as I want them to, so you will have to test a little; it's 4:55 Am here so I'm not gonna test it right now.

Tell me what are the results.

BTW you would want to not check spaces and special characters as people would just write a bunch of spaces to trick the system.
 
This is just assuming the following effect is syntactically correct
code_language.skript:
 set {_split::*} to message split at ""

Which would return a list variable with all characters in a message, and that comparing "A" with "a" would return that they're not equal.

Use that effect and then loop the variable, see if the letter is an uppercased letter and if it is, add 1 to a counter variable. Divide it by the size of the message and if the result is higher than 0.8, cancel the event.

Those are such specific cases that I have no clue if they work as I want them to, so you will have to test a little; it's 4:55 Am here so I'm not gonna test it right now.

Tell me what are the results.

BTW you would want to not check spaces and special characters as people would just write a bunch of spaces to trick the system.
This won't work because by default is/= is not case sensitive. You can, however, use split which is case sensitive
 
You can use regex and have it very short.
code_language.skript:
set {_l} to length of regex replace "[^A-Z]" with "" in <your text>
if {_l} > length of <your text> / 0.8:
You could technically make it a one-liner but that would kinda be going overboard. Requires TuSKe.
 
Status
Not open for further replies.