View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > Right PreviousNext

Right

Gets a specified number of characters from a string, beginning at the right.

String functions

Right(string, count)

Mid, Left, Reverse

Parameter

Description

string

A string or a variable that contains one

count

A positive integer or a variable that contains one. Number of characters to return.

<h3>Right Example</h3>
<cfif IsDefined("Form.MyText")>
<!--- if len is 0, then err --->
   <cfif Len(FORM.myText) is not 0>
      <cfif Len(FORM.myText) LTE FORM.RemoveChars>
      <p>Your string <cfoutput>#FORM.myText#</cfoutput>
      only has <cfoutput>#Len(FORM.myText)#</cfoutput>
      characters. You cannot output the <cfoutput>#FORM.removeChars#
     </cfoutput>
      rightmost characters of this string because it is not long enough
      <cfelse>
      <p>Your original string: <cfoutput>#FORM.myText#</cfoutput>
      <p>Your changed string, showing only the 
<cfoutput>#FORM.removeChars#</cfoutput> rightmost characters: <cfoutput>#right(Form.myText, FORM.removeChars)# </cfoutput> </cfif> <cfelse> <p>Please enter a string </cfif> </cfif>

Contents > CFML Reference > ColdFusion Functions > Right PreviousNext

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

Version 6.1

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

Comments


Sarge said on Mar 19, 2004 at 4:21 PM :
Consider alphabetizing the related functions.
Sarge said on Mar 19, 2004 at 4:26 PM :
Consider modify the definition to say:

Returns the count of characters from the end of the string argument.

String; the rightmost count characters at the end of the string.
Sarge said on Mar 20, 2004 at 9:24 AM :
We are working to improve the examples in the ColdFusion reference pages. We propose to replace the current example on this page with the the following example. If you have any comments on this example, add them to this page.

This example shows how to use the right function to return the rightmost count of characters.

<h3>Right Example</h3>
<cfif IsDefined("Form.MyText")>
<!--- If len returns 0 (zero), then show error message. --->
<cfif Len(FORM.myText)>
<cfif Len(FORM.myText) LTE FORM.RemoveChars>
<cfoutput><p style="color: red; font-weight: bold">Your string #FORM.myText#
only has #Len(FORM.myText)#
characters. You cannot output the #FORM.removeChars#
rightmost characters of this string because it is not long enough.</p></cfoutput>
<cfelse>
<cfoutput><p>Your original string: <strong>#FORM.myText#</strong>
<p>Your changed string, showing only the <strong>#FORM.removeChars#</strong> rightmost characters:
<strong>#right(Form.myText, FORM.removeChars)#</strong></p></cfoutput>
</cfif>
<cfelse>
<p style="color: red; font-weight: bold">Please enter a string of more than 0 (zero) characters.</p>
</cfif>
</cfif>

<form action="<cfoutput>#CGI.ScriptName#</cfoutput>" method="POST">
<p>Type in some text<br />
<input type="Text" name="myText"></p>
<p>How many characters from the right do you want to show?
<select name="RemoveChars">
<option value="1">1
<option value="3" selected>3
<option value="5">5
<option value="7">7
<option value="9">9</select>
<input type="Submit" name="Submit" value="Remove characters"></p>
</form>
No screen name said on Jun 2, 2004 at 11:17 PM :
Why not show the function/tag with the values returned in isolation from lots of code which can be distracting, especially if you do not understand all the other tags/functions involved.

eg: Right(string, count)

So, Right(string, 3) returns "ing"

You can still use the extra coding to show an example of the tag/function in use.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functa74.htm