Subsribe to our RSS

latest reactions

Dark
I saw more of this staff at http://loadi …
Sean
What about if it isn't in a session, but …
Tjarko
Strange thing however is that the same s …
jax
another option.. replace the path separa …
jax
Load the file into eclipse and turn on ' …

mxna feeds

Error opening the editorColdfusion Tutorial : Hold OutputMore New Adobe Topics - Adam Lehman and Tom JordahlPlease Welcome Rachel Luxemburg to AdobeNew Mango Blog Plugin: Auto PingColdFusion 9 Feature Request: Drop Ajax/JS librariesNew Version of Feed Ping for Mango BlogSite Map Generator: Mango Blog PluginColdFusion Demos v. 2Playing with jQuery - ColdFusionBloggers.org UpdateFree ColdFusion Training by ColdFusion User Group, IndiaHow to change ColdFusion / JRun logging locationSpeakers getting ready for CFUnitedWeb standards awareness among CF developersUsing ColdFusion to create an Encryption / Decryption Key from Plain Text

All files are strictly confidential: all information is classified.
© Copyright 2002 - 2008 mximize.com.
All right reserved.

MXNA webfeed

Visit Carlos GallupaPowered by ColdFusion MX 7.01

Simple InitCap function for coldfusion


<cffunction name="initcap" returntype="string" output="no">
 <cfargument name="str" required="yes" type="string">
 <cfset var capStr = "">

 <!--- Uppercase the first character --->
 <cfset capStr = ucase(left(arguments.str,1)) & lcase(mid(arguments.str,2, len(arguments.str)-1))>

 <cfreturn capStr>
</cffunction>

1956 viewed | 7 opinion(s)  | del.icio.us | Digg it | Tjarko @ 14/12/06 12:35 cet


Reactions:

Sam Farmer wrote.... (mail)

Nice.

This also works as well:

capStr = ReReplace(capStr,"(.)","\u\1")

14 December 2006 15:02 cet  

Tjarko wrote....

Even better.. short coding.. fewer characters.. nice!!

14 December 2006 15:03 cet  

Ben Nadel wrote.... (site)

One more twist on the RegEx method:

REReplace( capStr, "([a-z]{1})", "\U\1", "ONE" )

By telling it explicitly it has to macth on lower case values only, then it only performs the uppercase when required. Using the (.) notation, it will always perform the uppercase, even if the first letter is already upper case.

Cheers.

14 December 2006 22:34 cet  

Steven Erat wrote.... (site)

Nice... I've been using a less than elegant home grown solution for this.

07 February 2008 17:07 cet  

Steve wrote....

Sorry, but INITCAP (in Oracle) changes the first letter of a word or series of words into uppercase.Also, it notes the presence of symbols, and will INITCAP any letter that follows a space or a symbol, such as a comma, period, colon, seimcolon, !, @, #, $, and so on.The examples given here will only uppercase the 1st occurrence of a lower case letter

19 February 2008 22:24 cet  

Tjarko wrote.... (site)

True.. but I wanted a function that would only uppercase the first letter. You can easily change this function to do what the Oracle function does and uppercase every letter of a word, but that was not my intention.

20 February 2008 9:02 cet  

Steve wrote.... (site)

But, REReplace( capStr, "([a-z]{1})", "\U\1", "ONE" ) will uppercase the 1st lower case letter it encounters, not necessarily the first.So, "THis might not be what you had in mind"would be returned "THIs might not be what you had in mind".One would assume the intent was to have a string returned with ONLY the FIRST alphabetic character uppercased.

22 February 2008 18:18 cet  

Leave your comment

Your name


Your url/website/link/email....


Some room for your reaction is placed here..



A dozen apples are how many?? (12 would be a good answer for this)




URL en mail addresses are translated for you... life sometimes is that simple!!
profile-manuscript