CFLib.org – Common Function Library Project

capFirstList(str[, delimiter])

Last updated May 30, 2010

author

Randy Johnson

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Capitalize the first letter of each item in a list.

Return Values:
Returns a string.

Example:

<cfoutput>#capFirstList("apple,orange,grape")#</cfoutput>

Parameters:

Name Description Required
str List to parse. Yes
delimiter List delimiter. Defaults to a comma. No

Full UDF Source:

<!---
 Capitalize the first letter of each item in a list.
 
 @param str      List to parse. (Required)
 @param delimiter      List delimiter. Defaults to a comma. (Optional)
 @return Returns a string. 
 @author Randy Johnson (randy@cfconcepts.com) 
 @version 1, May 30, 2010 
--->
<cffunction name="capFirstList" returntype="string" output="false">
    <cfargument name="str" type="string" required="true" />
    <cfargument name="delimiter" default="," required="false">

    <cfset var newstr = "" />
    <cfset var word = "" />
    <cfset var separator = "" />

    <cfloop index="word" list="#arguments.str#" delimiters="#arguments.delimiter#">
        <cfset newstr = newstr & separator & UCase(left(word,1)) />
        <cfif len(word) gt 1>
            <cfset newstr = newstr & right(word,len(word)-1) />
        </cfif>
        <cfset separator = arguments.delimiter />
    </cfloop>

    <cfreturn newstr />
</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