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.
count
, the rightmost count
characters of the string
count
is greater than the length of the string, the whole string
count
is greater than 1, and the string is empty, an empty string
Right(string
,count
)
Parameter |
Description |
---|---|
string |
A string or a variable that contains one. |
count |
A positive integer that specifies the number of characters to return. |
<!--- 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> </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>