Monday, August 8, 2011

ColdFusion: Capitalize every word using regex

Forget about loops, left, right, mid and writing multiline custom functions.  Since ColdFusion MX, all you need is rereplace.
To capitalize ever word in a string: rereplace(string,"\b(\w)","\u\1","all")

2 comments:

  1. How would you make this so it only capitalizes words longer than 3 characters? For example, ignore the word 'and' or 'or'... thanks for the example!

    ReplyDelete