You are here:
ColdFusion - a middleware web server technology from Adobe ColdFusion - a middleware web server technology from Adobe

Capitalize the first letter in every word using ColdFusion | Regex to the rescue

I recently needed to capitalize (uppercase) the first letter of every word in a string. Without messing around using left, right, mid, FindNoCase, I found a handy snippet of code that uses a regular expression (regex) to do the trick.

The code goes a little bit like this:

ReReplace(str,"\b(\w)","\u\1","ALL")

This is a case sensitive replacement. To alter this simply use "ReReplaceNoCase" instead of ReReplace.

Nice, quick efficient and simple.