Convert a string To Title Case
February 18, 2019
A question came up on the CFML Slack channel today about converting a string to Title Case. I thought I’d see if I could solve it using a regular expression and this is what I came up with:
s = "iTSy bITSY TeeniE wEENIE Yellow pOLKADOT BiKiNi"; titleCase = REReplaceNoCase(s, "\b(\w)(\w+)\b", "\U\1\L\2", "all"); writeDump(titleCase); // Itsy Bitsy Teenie Weenie Yellow Polkadot Bikini
I tested this on ACF10, ACF11, ACF2016, ACF2018 and Lucee.
More like this
Top recommended articles