/

A Simple Title Case function for ColdFusion

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.

RSS Feed

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!

Theme Design by devolux.org
Background credits to Snoqualmie Dew By Lyle Krannichfeld

Followers