CapFirst(string)
Last updated March 9, 2007
Version: 2 | Requires: ColdFusion MX | Library: StrLib
Description:
Returns the string with the first character of each word capitalized.
Return Values:
Returns a string.
Example:
<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
Tayo Akinmade added
arrayTrim
3 day(s) ago
Will Belden added
longTime
9 day(s) ago
James Sleeman added
quickSort
19 day(s) ago
Ben Forta added
GetHostAddress
22 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)