Link to home
Start Free TrialLog in
Avatar of hefterr
hefterrFlag for United States of America

asked on

ColdFusion: Proper Case Function?

Hi,
I was wondering if someone could point me to a solid UDF, UDT or CFC that takes a string of "words" and converts them into proper "title case".  This is where
-  the first letter of each word is uppercase
-  rest of each word is lower case
-  does not capitalize words that are prepositions, articles (you know - the small connector words)
-  Handles some common abbreviations?

You know what I mean (I hope).

Thanks in advance,
hefterr
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hefterr

ASKER

The CapFirstTitle is close to what I am looking for.  Just one more related question.  How does one test a string in CF to see if the alphabetic characters are all upper case?  It's related because I beleive this is why my boss wants to use this function.
like this:

<cfif str neq ucase(str)>
Incorrect
<cfelse>
Correct
</cfif>
> <cfif str neq ucase(str)>

Not quite. NEQ is case *insensitive*

You can either use a regex or compare() the string to the upper case version (compare is case sensitive)

      <cfif compare( someString, ucase(someString)) eq 0>
            all upper case
      <cfelse>
            NOT all upper case
      </cfif>
Avatar of hefterr

ASKER

Thanks for your help.
but agx, NEQ will work, Can you explain me better why?
Nope, it won't. NEQ doesn't care about case so it treats "apple" and "APPLE" the same.