Home >> Snippet List >> Snippet

Name
Count capital letters in a string
Description
Two easy ways to find how many capital letters there are in a string
PHP Snippet
FUNCTION count_capitals($str) {
  RETURN STRLEN(PREG_REPLACE('![^A-Z]+!', '', $str));
}
 
 
// or...
 
STR_REPLACE(RANGE('A', 'Z'), '', $str, $num_caps);
 
PRINT "Number of capital letters: $num_caps";