rightstr(X;Y)

Returns a string consisting of the last number of characters of a given string, or all but the first number of characters of a given string. (Available as of version 16.09)

Syntax

rightstr(X;Y)

Input

Argument Type Description
X text The string on which to apply the function

A scalar value or the name of a column

Y integer For positive values of Y, the number of characters to extract from X, starting with the last character. For negative values of Y, extract all but the first Y characters.

Return Value

For positive values of Y, returns a text string comprised of the last Y characters of X.

For negative values of Y, returns a text string comprised of all but the first Y characters of Y

Sample Usage

value number rightstr(value;number)
'testing' 3 'ing'
'testing' -3 'ting'
'testing' 2 'ng'
'testing' -2 'sting'

Example

In the "Product Master" table (pub.demo.retail.prod), you can extract the substrings consisting of the last four characters of the department descriptions. To do this, create a computed column and apply the rightstr(X;Y) function to the deptdesc column:

<base table="pub.demo.retail.prod"/>
<willbe name="example" value="rightstr(deptdesc;4)"/>

The results are the last four characters of the values in the deptdesc column.

For example, the result for the department description named "FOOTWEAR" would be "WEAR". The result for the department description named "OFFICE SUPPLIES" would be "LIES".

Additional Information

rightstr(X;Y) is similar to last(X;Y), with the exception that it can handle negative Y arguments. rightstr(X;Y) may be more convenient for certain applications, such as when porting code from other languages.