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>
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