You need to return a string with the first letter of every word in uppercase.
Use listMap
and break out the resultant words to fix the string.
string function initCap(required string phrase) {
// map over the string dividing words by spaces
return listMap(
arguments.phrase,
function(word) {
return '#uCase(left(word, 1))##lCase(right(word, len(word) - 1))#';
},
' '
);
}
This is included in our common_utils module available in all 5.5 or newer apps (older apps can find it in the common_utls.cfm file).
#initCap('the quick BrOwN fox')#
outputs: "The Quick Brown Fox"