Skip to main content

$REVERSE

Returns the characters in a string in reverse order.

Synopsis

$REVERSE(string)
$RE(string)

Parameter

Argument Description
string A string or expression that evaluates to a string.

Description

$REVERSE returns the characters in string in reverse order. The string can contain 8-bit characters or 16-bit Unicode characters. For further details on Caché Unicode support, refer to Unicode in Using Caché ObjectScript.

Surrogate Pairs

$REVERSE does not recognize surrogate pairs. Surrogate pairs are used to represent some Chinese characters and to support the Japanese JIS2004 standard. You can use the $WISWIDE function to determine if a string contains a surrogate pair. The $WREVERSE function recognizes and correctly parses surrogate pairs. $REVERSE and $WREVERSE are otherwise identical. However, because $REVERSE is generally faster than $WREVERSE, $REVERSE is preferable for all cases where a surrogate pair is not likely to be encountered.

Examples

The following WRITE commands shows the return value from $REVERSE. The first returns “CBA”, the second returns 321.

   WRITE !,$REVERSE("ABC")
   WRITE !,$REVERSE(123)

You can use the $REVERSE function with other functions to perform search operations from the end of the string. The following example demonstrates how you can use $REVERSE with the $FIND and $LENGTH functions to locate the last example of a string within a line of text. It returns the position of that string as 33:

   SET line="THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG."
   SET position=$LENGTH(line)+2-$FIND($REVERSE(line),$REVERSE("THE"))
   WRITE "The last THE in the line begins at ",position

See Also

FeedbackOpens in a new tab