About Me
- Jay Proulx
- Ottawa, ON, Canada
- Senior RIA consultant with a focus on Adobe's arsenal of platform products.
There are a number of long winded title case functions out there available for ColdFusion, so I thought I would share a short one. ColdFusion has a couple of interesting back reference characters for regular expression replaces (documentation here).
<cfscript>
function tcase(str) {
return rereplace(lcase(str), "(.*?)(\b)", "\u\1\2 ", "ALL");
}
</cfscript>
Effectively, find each word by a word boundary, and use the \u back reference to uppercase the first letter in the word.
1 Comment for A Simple Title Case function for ColdFusion
John Lichty | November 16, 2010 at 9:54 AM
Works beautifully! Thank you!
Leave a comment!