Simple Title case regex





7
Date Submitted Mon. Nov. 6th, 2006 1:48 PM
Revision 1 of 1
Helper RobHarrigan
Tags "first | "title | capitalize | case" | letter" | Perl
Comments 3 comments
Function to capitalize the first letter in every word in a string, but only if the entire string is in ALL CAPS.

Example:
"I LIKE TO SCREAM" becomes "I Like To Scream"
"I LIKE to RUN" remains "I LIKE to RUN".


sub deScreamer{

        $str=shift;

        if($str!~m/[a-z]/){
           $str=lc($str);     
           $str=~s/\b(\w)/uc($1)/eg; 
        }

        return str;
}

 

rob Harrigan

Comments

Comments Acronyms
Mon. Nov. 13th, 2006 8:42 AM    Beginner Mattkins
  Comments About Acronyms
Mon. Nov. 13th, 2006 3:12 PM    Helper RobHarrigan
Comments This maybe will work
Thu. Nov. 16th, 2006 6:24 PM    Newbie aelander

Voting