Cloud Photo

Azure Data Architect | DBA

ColdFusion Sentence Case

I wanted to normalize text entered by users so that I could collect stats. So I SQL’d something like this…
select count(1) as total, upper(nvl(resp,’NO RESPONSE’)) as resp from forms.form_field_resp where ffid=#id# group by upper(nvl(resp,’NO RESPONSE’)) order by total desc

But I didn’t want to display the text in all CAPS BECAUSE THAT’S PRETTY DANG ANNOYING. So I rigged this to set the very first character to upper case and then replace every character after a period to upper case and leave everything else as lower case so it looks more like a sentence. It’s not perfect and I need to account for ? and !, but here’s my stupid trick for the day.

#ucase(left(resp,1))##mid(REReplace(lcase(resp),”\. ([[:lower:]]*)”,”. \u\1″,”ALL”),2,9999)#

Of course, Kevin improved it…
To get the other chars, (and take into account different spacing) this should work:

REReplace(lcase(resp), “([\.!?])\s*([[:lower:]]*)”, “\1 \u\2”, “ALL”)

Leave a Reply