UDF: pcase() - Captilize first letter of each word in a string
ColdFusion, Tips and Tricks, Technology, CFML, UDF
This is a UDF that I keep on hand for converting strings to "proper case", such as a person's name. For instance, in a database we might have a name stored like DAVID B. SHUCK, but when they log into our site and we welcome them, we don't necessarily want to shout it at them! Saying "Hello David B. Shuck..." would hopefully be a bit less abrasive.
Enter the user-defined function pcase(). Through the use of regular expressions we are doing a search for word patterns and capitalizing the first letter in each word. Enjoy!
Enter the user-defined function pcase(). Through the use of regular expressions we are doing a search for word patterns and capitalizing the first letter in each word. Enjoy!
<cffunction name="pcase" access="public" output="false" returntype="string">
<cfargument name="string" type="string" required="true" />
<cfreturn REReplaceNoCase(LCase(arguments.string),"(^[a-z*]|[ *][a-z*])","\U\1\E","all") />
</cffunction>





Loading....