Function Right() Foundation

Extracts part of a character string starting from the end (right).

Syntax
Right( <cString>, <nCount> ) --> cSubString
Parameters
<cString>
<cString> is a character string from which a character substring is extracted from the end (from the right). The maximum length of <cString> is not limited with Xbase++.
<nCount>
<nCount> is the number of characters extracted from <cString>.
Return

Right() returns the last <nCount> characters from <cString> as a character string. When <nCount> equals zero, a null string ("") is returned. When <nCount> is negative or greater than the length of <cString>, <cString> is returned.

Description

The character function Right() extracts part of a character string beginning with the last character. The result is the same as with the call SubStr(<cString>, -<nCount>). The counterpart of Right() is the function Left(), which extracts part of a character string starting at the beginning (left).

The functions Left(), Right() and SubStr() extract parts of character strings. They are often used with the functions At() and RAt(), which determine the position of a substring within a character string.

Examples
Right()
// The example shows various results of the function Right(). 

PROCEDURE Main 

   ? Right("Xbase++", 2)        // result: ++ 
   ? Right("CUSTOMER.DBF",3)    // result: DBF 

RETURN 
Extract file extension

// The example extracts the file extension 
// from a file name. 

PROCEDURE Main 
   LOCAL cFileName := "C:\XBASE\APPS\DBF\CUSTOMER.DBT" 

   ? Extension( cFileName )     // result: DBT 

RETURN 

FUNCTION Extension( cFileName ) 
   LOCAL cExtension := "", i := RAt( ".", cFileName ) 
   IF  i > 0 
     cExtension := Upper( Right( cFileName, Len(cFileName)-i ) ) 
   ENDIF 

RETURN cExtension 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.