EasyCFM.COM ColdFusion Forums / Good Coding Tips! / Title Case Function

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Title Case Function -- page: 1 2

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

MIGhunter
11-20-2009 @ 11:38 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 570
Joined: Apr 2006

I've been using this version for a long time:

<!--- Capitalizes 1st letters of names --->
<!---
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>


PAGE: 1 2

Website Designed and Developed by Pablo Varando.