View comments | RSS feed

UCase

Description

Converts the alphabetic characters in a string to uppercase.

Return value

A copy of a string, converted to uppercase.

Category

String functions

Syntax

UCase(string)

See also

LCase

Parameters

Parameter Description
string
A string or a variable that contains one

Example

<h3>UCase Example</h3>

<cfif IsDefined("FORM.sampleText")>
  <cfif FORM.sampleText is not "">
    <p>Your text, <cfoutput>#FORM.sampleText#</cfoutput>, 
returned in uppercase is <cfoutput>#UCase(FORM.sampleText)#</cfoutput>.
  <cfelse>
    <p>Please enter some text.
  </cfif>
</cfif>

<form action = "ucase.cfm">
<p>Enter your sample text, and press "submit" to see the text returned in
uppercase:
<p><input type = "Text" name = "SampleText" value = "sample">

<input type = "Submit" name = "" value = "submit">
</form>

ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


Anubis^HH said on Oct 22, 2003 at 1:33 PM :
it would also be nice if Macromedia implements a function that converts the First letter of a string to Upper Case, "title case". it might be called for example UCaseFirst

<cfoutput>UCaseFirst("some string")</cfoutput>
result: Some String
No screen name said on May 4, 2004 at 11:57 AM :
Here's one way to only capitalize the first letter in a word:

#Left( UCase( "word" ), 1 )##Right( LCase( "word" ), Len( "word" ) - 1 )#
dannymather said on Sep 15, 2004 at 2:24 PM :
another easy way to capitalize text is to apply a bit of CSS formatting to it.
<p style="text-transform: capitalize;">hello world</p>
would output: Hello World
blewington said on Mar 22, 2005 at 1:02 PM :
Yes, Left( UCase( "word" ), 1 )##Right( LCase( "word" ), Len( "word" ) - 1 )# would generally work but what about:

Word you never want to capitalize (e.g. and or)
Words you always want to capitalize (e.g. USA)
hotani said on May 11, 2005 at 3:42 PM :
RE: capitalizing first character of strings

by using a variant of the code above, you can throw this in your Application.cfm page:
<cfscript>
// capitalize first letter of string
function capCase(word)
{ return left(uCase(word),1) & right(lCase(word),len(word)-1);
}
</cfscript>

now capitalize words with capCase("string")
No screen name said on Apr 30, 2007 at 3:05 PM :
Using a few functions I found on the site referenced below, I have created a few functions that can help with Title Case.

In the titleCase function you'll notice a few commented out code lines. this is where you can write in exceptions you want for your title case such as 'USA' or 'of.'

<cfscript>
/** from http://www.sitepoint.com/article/defined-functions-coldfusion */
function isUpperCase(character)
{
if (Asc(character) gte 65 and Asc(character) lte 90)
return true;
return false;
}
/** from http://www.sitepoint.com/article/defined-functions-coldfusion */
function isLowerCase(character)
{
if (Asc(character) gte 97 and Asc(character) lte 122)
return true;
return false;
}
/** from http://www.sitepoint.com/article/defined-functions-coldfusion */
function isUpperOrLowerCase(character)
{
if (Asc(character) gte 65 and Asc(character) lte 90)
return true;
else if (Asc(character) gte 97 and Asc(character) lte 122)
return true;
return false;
}
/** nameTitleCase
* This function will check a string to see if it is in Name title case
*
* @param nameString This is the string that needs to be changed
*
* @return returns true if it is of title case, false if it is not
*/
function isNameTitleCase(nameString)
{
var previousChar = " ";
var i = 0;
for(i = 1; i LTE Len(nameString); i = i + 1)
{
thisChar = mid(nameString,i,1);
if(previousChar is " " or previousChar is "-" or previousChar is "'")
{
if(isLowerCase(thisChar) and isUpperOrLowerCase(thisChar))
{
return false;
}
}
else
{
if(isUpperCase(thisChar) and isUpperOrLowerCase(thisChar))
{
return false;
}
}

previousChar = thisChar;
}
return true;
}
/** titleCase
* This function will take a name and make it into a title case
*
* @param nameString This is the string that needs to be changed
*
* @return finalString The final string will be the same information as was entered into the function but in title case
*/
function titleCase(nameString)
{
var tempString = nameString;
var finalString = "";
var previousChar = " ";
var i = 0;
for(i = 1; i LTE Len(tempString); i = i + 1)
{
if(previousChar is " " or previousChar is "-" or previousChar is "'"){tempChar = UCase(mid(tempString,i,1));}
else{tempChar = lcase(mid(tempString,i,1));}

previousChar = mid(tempString,i,1);
finalString = finalString & tempChar;
}
/*if(find("Of",finalString) GT 1){finalString = replace(finalString,"Of","of","All");}
if(find("The",finalString) GT 1){finalString = replace(finalString,"The","the","All");}
if(find("A ",finalString) GT 1){finalString = replace(finalString,"A ","a ","All");}*/
return finalString;
}
</cfscript>

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt2110.htm