hefterr
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)>
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>
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>
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.
http://cflib.org/udf/CapFirst
http://cflib.org/udf/capFirstList
http://cflib.org/udf/celticMcCaps
http://cflib.org/udf/UCaseAll