Function group Execute on client Platform(s)
String YES All

Syntax

right(string,n)

right(string,n[,mode=kLeftRightCount])

Description

Returns the substring comprising the last n characters of the string.

Example

Calculate lResult as right('Elephant',3)
# returns 'ant'

Returns the last n characters of the string. If mode is kLeftRightSearchExclude or kLeftRightSearchInclude, n is a search string and the result starts after or at its last occurrence or is #NULL.

The optional mode parameter takes one of the String search modes constants, and says how n is used:

In the search modes:

right('File.Field','.',kLeftRightSearchExclude)
; returns 'Field'
right('File.Field','.',kLeftRightSearchInclude)
; returns '.Field'
right('Lib.File.Field','.',kLeftRightSearchExclude)
; returns 'Field' (the last occurrence)
right('ABC1ABC2ABC1ABC3','ABC',kLeftRightSearchInclude)
; returns 'ABC3'
right('File.','.',kLeftRightSearchExclude)
; returns '' (the match is at the end)
right('File.Field','field',kLeftRightSearchExclude)
; returns #NULL (the search is case sensitive)
right('0123456789',5)
; returns '56789' (a character count, as before)

#NULL is not the same as an empty string, and functions treat it differently: con() and len() treat it as empty, while others such as upp() return #NULL. Test the result with isnull() when the search string might be missing; see example.

Example

Calculate lFieldNamePart as right(lFieldName,'.',kLeft)
If isnull(lFieldNamePart)
  Calculate lFieldNamePart as lFieldName
End If