CFLib.org – Common Function Library Project

humanize(text)

Last updated May 17, 2007

author

Christopher Warren

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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson