$iscaps - % of capital or lowercase

By Scakk on Jun 07, 2008

The below snippet with tell you the percentage of capital letters , lowercase letters or both. It will only take into account letters in the string being checked.

Update: Removed variables and placed $regex inside $calc itself. Also made the % optional for each version. ( June 9th '08 )

Update: Redid the code a bit to make it shorter and easier to use. ( August 27th '08 )

;http://www.hawkee.com/snippet/3325/ ( based off of )
;--- Usage ----------------
;--- $iscaps(string).u <-- %caps
;--- $iscaps(string).up <-- %caps /w % after number
;--- $iscaps(string).l <-- %lowercase
;--- $iscaps(string).lp <-- %lowercase /w % after number
;--- $iscaps(string) <-- %caps , %lowercase
;--- $iscaps(string).p <-- %caps , %lowercase /w % after numbers
;--------------------------

;http://www.hawkee.com/snippet/3325/ ( based off of )
;--- Usage ----------------
;--- $iscaps(string).u  <-- %caps
;--- $iscaps(string).up  <-- %caps /w % after number
;--- $iscaps(string).l <-- %lowercase
;--- $iscaps(string).lp <-- %lowercase /w % after number
;--- $iscaps(string)  <-- %caps , %lowercase
;--- $iscaps(string).p  <-- %caps , %lowercase /w % after numbers
;--------------------------
alias iscaps { 
  if ($isid) {
    if (u isin $prop) { 
      return $+($round($calc( $regex($1,/[A-Z]/g) / $regex($1,/[A-Z]/gi) * 100),2),$iif(p isin $prop,$chr(37)))
    }
    if (l isin $prop) { 
      return $+($round($calc( $regex($1,/[a-z]/g) / $regex($1,/[A-Z]/g) * 100),2),$iif(p isin $prop,$chr(37)))
    }
    if (!$prop || $prop == p) {
      return $+($round($calc( $regex($1,/[A-Z]/g) / $regex($1,/[A-Z]/gi) * 100),2),$iif(p isin $prop,$chr(37))) , $&
        $+($round($calc( $regex($1,/[a-z]/g) / $regex($1,/[A-Z]/gi) * 100),2),$iif(p isin $prop,$chr(37)))
    }
  }
}

Comments

Sign in to comment.
vaseline28   -  Jun 11, 2008

Much neater now as you said on IRC! I think it deserves a higher rating now, great work!

 Respond  
Scakk   -  Jun 09, 2008

Bahamut: Varaiables are now more as I have placed the $regex itself inside the $calc. Also made the % option for each version.

 Respond  
vaseline28   -  Jun 09, 2008
 Respond  
^Neptune   -  Jun 09, 2008

Damn it, this is great.
I really want to learn regex but not sure how :(

 Respond  
Bahamut   -  Jun 08, 2008

Eh, it works at the very least, but the coding is not really stunning. Perhaps only declare variables once? Also, there are some letters you are missing support for (A-ZŠŒŽÀ-ÖØ-ÞŸ).

Now besides the coding: I find that adding a % to the end of the returned value is completely useless. What if I wanted to use this for a caps kicker? I\'d have to use $remove or $left or so.

But in any case, this is a nice example of regex and how it can be used. Perhaps add a .count property to return the total matches (basically without a percentage)? Good luck.

 Respond  
Scakk   -  Jun 08, 2008

It was .ul at one time but later I changed to not need that. Got it correct in the snippet itself. Changed it in the introduction part now. Thanks for the heads up.

 Respond  
vaseline28   -  Jun 08, 2008

Nice work also.

You say in introduction the usage is:
$iscaps().ul
But in the script it seems as though the usage for that is just $iscaps()

 Respond  
EL   -  Jun 07, 2008

Nice work Scakk.`-.-´

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.