Blog Post RSS ?

Blogs » ColdFusion » Upper case / Lower case functions
 

Upper case / Lower case functions

by davidjmedlock

…posted by davidjmedlock:

This originated out of some project I was thinking about doing and I though it’d be useful for others. These functions check to see if a character is upper case or lower case:

function isUpperCase(character) { if (Asc(character) gte 65 and Asc(character) lte 90) { return true; } else { return false; } } function isLowerCase(character) { if (Asc(character) gte 97 and Asc(character) lte 122) { return true; } else { return false; } } #isUpperCase("A")#
#isLowerCase("A")#
#isUpperCase("a")#
#isLowerCase("a")#

Have fun with it.

This post has 3 responses so far

  1. Forgot to add this:

    if (Len(character) gt 1) return false;

    to the top of each of those functions. That way if they pass in a string, it won’t bomb. (It shouldn’t anyway. It should just return whether the first character is upper or lowercase…)

     
  2. Nice - we might actually use that one. We love CF functions.

    Be sure to add it to cflib.org!

    Tony

     
  3. What about a whole string? Here’s my function:

    function stringIsUppercase(str) {
    if(reFind(”^[A-Z]+$”,arguments.str)) return true;
    else return false;
    }

     

Sponsored Links

Leave a response

You are not logged in, log in with your SitePoint Forum username and password.

-OR- Post Anonymously

* Make sure any code samples are escaped (i.e. ‘<b>’ becomes ‘&lt;b&gt;’).

If not logged in, your comments will be placed in a moderation queue. This means your comment may not appear until one of our moderators approves it.

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.