User Guide
Right 825
Right
Description
Gets a specified number of characters from a string, beginning at the right.
Returns the specified number of characters from the end (or right side) of the specified string.
Returns
• If the length of the string is greater than or equal to count, the rightmost count characters of
the string
• If count is greater than the length of the string, the whole string
• If count is greater than 1, and the string is empty, an empty string
Category
String functions
Function syntax
Right(string, count)
See also
Left
, Mid, Reverse
Parameters
Example
<!--- Simple Right Example--->
<cfoutput>
#Right("See the quick red fox jump over the fence", 9)#
<br>
#Right("ColdFusion", 6)#
</cfoutput>
<!--- Right Example using form input --->
<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>
Parameter Description
string A string or a variable that contains one.
count A positive integer that specifies the number of characters to return.