CFLib.org – Common Function Library Project

nameCase(string)

Last updated January 02, 2006

author

Jared Rypka-Hauer

Version: 2 | Requires: CF6 | Library: StrLib

Description:
This uses a simple example of regex processing to convert ALL UPPER CASE STRINGS to Name Case Strings using CF's built-in case processing technology in the regex functions.

Return Values:
Returns a string.

Example:

<cfoutput>#nameCase("JARED RYPKA-HAUER")#</cfoutput>

Parameters:

Name Description Required
string String to format. Yes

Full UDF Source:

<!---
 Converts an entire string to namecase (JARED RYPKA-HAUER becomes Jared Rypka-Hauer).
 
 @param string      String to format. (Required)
 @return Returns a string. 
 @author Jared Rypka-Hauer (jared@web-relevant.com) 
 @version 2, January 1, 2006 
--->
<cffunction name="nameCase" access="public" returntype="string" output="false">
    <cfargument name="name" type="string" required="true" />
    <cfset arguments.name = ucase(arguments.name)>
    <cfreturn reReplace(arguments.name,"([[: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

Created by Raymond Camden / Design by Justin Johnson