titleCaseList(list[, delimiters])
Last updated May 22, 2014
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 & 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");
}
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