Thursday, March 11, 2010

Uppercase First

Something simple to start with. ColdFusion comes with functions to uppercase and lowercase strings - ucase(string) and lcase(string). There is currently no function to uppercase the first character then lowercase the remaining characters of a string. Here is the solution:
Uppercase the first character of each word in the string:
Snippet: #reReplace('text string',"(^[a-z]|\s+[a-z])","\U\1","ALL")#
Input: 'text string'
Output: 'Text String'

Uppercase the first character of the first word in the string:
Snippet: #reReplace('text string',"(^[a-z])","\U\1","ALL")#
Input: 'text string'
Output: 'Text string'

No comments:

Post a Comment