Bukz

tolower/upper & convertcase concept

May 8th, 2011
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. lowAlphaList = "a b c d e f g h i j k l m n o p q r s t u v w x y z"
  2. hiAlphaList = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
  3.  
  4. tolower = [
  5.   tmpArg1 = $arg1; tmpFindList = (findlist $hiAlphaList $tmpArg1)
  6.   if (>= $tmpFindList 0) [
  7.     tmpCOut = (at $lowAlphaList (findlist $hiAlphaList $tmpArg1))
  8.     result $tmpCOut
  9.   ] [ result $arg1 ]
  10. ]
  11. // echo (tolower a)    // Output: a
  12. // echo (tolower A)    // Output: a
  13. // echo (tolower AB)   // Output: AB   // Only works with single char arguments
  14. // echo (tolower 1337) // Output: 1337 // Ignores anything that is not an alpha char or is already in the desired case
  15.  
  16. toupper = [
  17.   tmpArg1 = $arg1; tmpFindList = (findlist $lowAlphaList $tmpArg1)
  18.   if (>= $tmpFindList 0) [
  19.     tmpCOut = (at $hiAlphaList (findlist $lowAlphaList $tmpArg1))
  20.     result $tmpCOut
  21.   ] [ result $arg1 ]
  22. ]
  23. // echo (toupper b) // Output: B
  24.  
  25. convertcase = [
  26.   tmpSCOut = ""
  27.   loop ccl (strlen $arg1) [
  28.     if (!= $arg2 0) [
  29.       tmpSCOut = (concatword $tmpSCOut (toupper (substr $arg1 $ccl 1)))
  30.     ] [
  31.       tmpSCOut = (concatword $tmpSCOut (tolower (substr $arg1 $ccl 1)))
  32.     ]
  33.   ]
  34.   result $tmpSCOut
  35. ]
  36. // echo (convertcase "HELLO WORLD")    // Output: hello world    // Default output is lowercase
  37. // echo (convertcase "HELLO WORLD" 1)  // Output: HELLO WORLD    // Use '1' as the 2nd argument to force into uppercase
  38. // echo (convertcase "hElLo WoRlD!!!") // Output: hello world!!! // Since it uses tolower/toupper, it ignores anything that is not an alpha char or is aleady in the desired case
Advertisement
Add Comment
Please, Sign In to add comment