humanize(text)
Last updated May 17, 2007
Version: 1 | Requires: CF5 | Library: StrLib
Description:
A step beyond Jared Rypka-Hauer's nameCase UDF (http://www.cflib.org/udf.cfm?ID=1384), I took this idea from Rails, and I'm sure they didn't do it first. It is especially useful in reading through database names and columns and formatting them for users. Nothing original, but pretty useful.
Return Values:
Returns a string.
Example:
<cfoutput>#humanize("first_name")#</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
text | String to parse. | Yes |
Full UDF Source:
<!---
Takes a string and humanizes it, removing underscores and capitalizing each word.
@param text String to parse. (Required)
@return Returns a string.
@author Christopher Warren (cwarren@imagetrend.com)
@version 1, July 23, 2007
--->
<cffunction name="humanize" access="public" returntype="string" output="false">
<cfargument name="text" type="string" required="true" />
<cfset arguments.text= ucase(arguments.text)>
<cfset arguments.text= replace(arguments.text,"_"," ","all")>
<cfreturn reReplace(arguments.text,"([[:upper:]])([[:upper:]]*)","\1\L\2\E","all") />
</cffunction>
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016