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

Reverse

Reverses the order of items, such as the characters in a string, the digits in a number, or the elements in an array.

A copy of string, with the characters in reverse order.

String functions

Reverse(string)

Left, Mid, Right

Parameter

Description

string

A string or a variable that contains one

You can call this function on a number with code such as the following:

<cfoutput>reverse(6*2) equals #reverse(6*2)#<cfoutput>

This code outputs the following:

reverse(6*2) equals 21

<h3>Reverse Example</h3>

<p>Reverse returns your string with the positions of the characters reversed.
<cfif IsDefined("FORM.myString")>
   <cfif FORM.myString is not "">
      <p>Reverse returned:
      <cfoutput>#Reverse(FORM.myString)#</cfoutput>
   <cfelse>
      <p>Please enter a string to be reversed.
   </cfif>
</cfif>

<form action = "reverse.cfm">
<p>Enter a string to be reversed:
<input type = "Text" name = "MyString">
<p><input type = "Submit" name = "">
</form>

Contents > CFML Reference > ColdFusion Functions > Reverse 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


ekkis said on Jul 15, 2004 at 8:18 AM :
this function is supposed to also sort arrays, unless I am understanding the description: "...or the elements in an array" wrongly. However, when I try:

var a = Reverse(StructKeyArray(rs));

I get:

Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.

wtf?? I have not found an alternative. Anyone with ideas can mail me, I'll be all ears!
ekkis said on Jul 15, 2004 at 8:30 AM :
found a solution at: http://cflib.org/library.cfm?ID=5

I guess I could have coded this myself but am astounded CF doesn't offer this functionality. anyway, the relevant function is pasted below.

- e@arix.com

/**
* Reverses the order of elements in a one-dimensional array.
*
* @param InArray One-dimensional array to be reversed.
* @return Returna a new one dimensional array.
* @author Raymond Simmons (raymond@terraincognita.com)
* @version 1.0, October 9, 2001
*/
function ArrayReverse(inArray){
var outArray = ArrayNew(1);
var i=0;
var j = 1;
for (i=ArrayLen(inArray);i GT 0;i=i-1){
outArray[j] = inArray[i];
j = j + 1;
}
return outArray;
}

 

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/functa73.htm