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
Ryan Thompson-Jewell added
ListSplit
1 day(s) ago
Nathan Dintenfass added
RowsToColumns
1 day(s) ago
Barney Boisvert added
indentXml
2 day(s) ago
Barney Boisvert added
REReplaceCallbac...
2 day(s) ago
Top Rated
FolderSize
Rated 5.0, 7 time(s)
UniqueValueList
Rated 5.0, 5 time(s)
QuickSort
Rated 5.0, 3 time(s)
ListDeleteDuplic...
Rated 5.0, 3 time(s)