CFLib.org – Common Function Library Project

titleCaseList(list[, delimiters])

Last updated May 22, 2014

author

Adrian Lynch

Version: 1 | Requires: CF9 | Library: StrLib

Description:
Title cases all elements in a list. Will change "adrian lynch" to "Adrian Lynch", "a.lynch" to "A.Lynch" and "a.christopher lynch-smith" to "A.Christopher Lynch-Smith"

Return Values:
Returns a string.

Example:

<cfset myString = "a.christopher lynch-smith">

<cfoutput>
Before: #myString#<br>
After: #TitleCaseList(myString, ".- ")#
</cfoutput>

Parameters:

Name Description Required
list List to modify. Yes
delimiters Delimiters to use. Defaults to a space. No

Full UDF Source:

/**
 * Title cases all elements in a list.
 * v1.0 by Adrian Lynch 
 * v1.1 by Adam Cameron. Simplified logic &amp; fixed a coupla bugs
 * 
 * @param list 	 List to modify. (Required)
 * @param delimiters 	 Delimiters to use. Defaults to a space. (Optional)
 * @return Returns a string. 
 * @author Adrian Lynch (adrian.l@thoughtbubble.net) 
 * @version 1.1, May 22, 2014 
 */
string function titleCaseList(required string list, string delimiters=" ") {
	var regexSafeDelims = reReplace(delimiters, "(.)(?=.)", "\1|", "ALL");
	return reReplace(list, "(^|[#regexSafeDelims#])(\w)", "\1\u\2", "ALL");
}
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