Function RTrim() Foundation

Deletes blank spaces at the end of a character string.

Syntax
RTrim( <cString> ) -->  cTrimString
Trim( <cString> ) -->  cTrimString
Parameters
<cString>
<cString> is a character string copied with trailing blank spaces removed.
Return

RTrim() returns a copy of <cString> with all blank spaces (Chr(32) only) at the end deleted. The function can be abbreviated as Trim(). When <cString> is an empty character string or only contains blank spaces, the return value is a null string ("").

Description

The character function RTrim() is used to format character strings whose last characters consist of blank spaces (Chr(32)). The functions RTrim() and Trim() are equivalent and provide identical results. RTrim() is often used when the contents of a database field are assigned to a memory variable and the variable needs to contain a character string without blank spaces at the end.

RTrim() resembles the function LTrim() which deletes blank spaces at the beginning of a character string. The function Alltrim() also deletes blank spaces and removes all blank spaces at the beginning and end of a character string. The counterparts of the functions LTrim(), RTrim() and Alltrim() are the functions PadL(), PadR() and PadC() which insert blank spaces at the beginning, end or both sides of a character string.

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

PROCEDURE Main 

   ? RTrim("Xbase++   ")          // result: "Xbase++" 
   ? RTrim("A ") + RTrim("Test ") // result: "ATest" 

RETURN 
Formatted output using RTrim()

// In this example, an address label is created with the 
// function RTrim(). 

#define CRLF   Chr(13)+Chr(10) 

PROCEDURE PrintLabel 
   USE Address NEW 
   SET DEVICE TO PRINTER 
   SET PRINTER ON 

   DO WHILE ! Eof() 
      ? AddressLabel( RecNo() ) 
      IF PCol() > 70 
         EJECT 
      ENDIF 
      SKIP 
   ENDDO 

   SET PRINTER OFF 
   SET DEVICE TO SCREEN 
   USE 
RETURN 

FUNCTION AddressLabel( nRecno ) 
   IF nRecno == NIL 
      nRecno := RecNo() 
   ENDIF 

   GOTO nRecno 

RETURN RTrim( FIRSTNAME ) + " "  + RTrim( LASTNAME ) + CRLF + ; 
       RTrim( ADDRESS ) + CRLF + ; 
       RTrim( CITY ) + ", " + RTrim(STATE) + " " + RTrim( ZIP ) 
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.