CFLib.org – Common Function Library Project

CapFirst(string)

Last updated March 9, 2007
Download UDF

author

Raymond Camden                                    Raymond Camden

Version: 2 | Requires: ColdFusion MX | Library: StrLib

 
Rated 10 time(s). Average Rating: 3.2

Description:
Returns the string with the first character of each word capitalized.

Return Values:
Returns a string.

Example:

<CFSET str="the dog jumped over the fox.">
<CFOUTPUT>
Given str=#str#<BR>
The CapFirst version is #CapFirst(str)#
</CFOUTPUT>

Parameters:

Name Description Required
string String to be modified. Yes

Full UDF Source:

<!---
Capitalizes the first letter in each word.
Made udf use strlen, rkc 3/12/02
v2 by Sean Corfield.

@param string      String to be modified. (Required)
@return Returns a string.
@author Raymond Camden (ray@camdenfamily.com)
@version 2, March 9, 2007
--->

<cffunction name="CapFirst" returntype="string" output="false">
    <cfargument name="str" type="string" required="true" />
    
    <cfset var newstr = "" />
    <cfset var word = "" />
    <cfset var separator = "" />
    
    <cfloop index="word" list="#arguments.str#" delimiters=" ">
        <cfset newstr = newstr & separator & UCase(left(word,1)) />
        <cfif len(word) gt 1>
            <cfset newstr = newstr & right(word,len(word)-1) />
        </cfif>
        <cfset separator = " " />
    </cfloop>

    <cfreturn newstr />
</cffunction>

Search CFLib.org


Latest Additions

Ryan Thompson-Jewell Ryan Thompson-Jewell added
ListSplit
1 day(s) ago

Nathan Dintenfass Nathan Dintenfass added
RowsToColumns
1 day(s) ago

Barney Boisvert Barney Boisvert added
indentXml
2 day(s) ago

Barney Boisvert Barney Boisvert added
REReplaceCallbac...
2 day(s) ago

Top Rated

Rob Brooks-Bilson                                 FolderSize
Rated 5.0, 7 time(s)

Nick Giovanni                                     UniqueValueList
Rated 5.0, 5 time(s)

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Jeff Howden ListDeleteDuplic...
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson