Functions and Directives

Function PadC() | PadL() | PadR() Foundation

Pads a character string, date or numeric value with fill characters

PadL( <Expression>, <nLen>, [<cFillChr>] ) --> cString
PadC( <Expression>, <nLen>, [<cFillChr>] ) --> cString
PadR( <Expression>, <nLen>, [<cFillChr>] ) --> cString
<Expression> is an expression having data type character, date or numeric. It is converted to a character string.
<nLen> is a positive integer indicating the length of the character string returned.
<cFillChr> specifies the fill character used to pad the character string after conversion from <Expression>. The blank space (Chr(32)) is the default fill character.

The return value of the functions PadC(), PadL() and PadR() is a character string with the length <nLen>. It contains the value of <Expression> as a string extended using the fill character <cFillChr> on the left, right or at both ends of the string.


The character functions PadC(), PadL() and PadR() are used for the formatted output of character, date or numeric values. The values are converted to a string which is extended using fill characters to the specified length. PadC() inserts fill character at both ends of the value of <Expression>, so that the value is centered in the character string. PadL() attaches the fill character to the left side of the character string and the value appears right justified. PadR() attaches the fill character at the right and the value appears left justified.

The character string returned has the length <nLen>. When the passed value of <Expression> results in a character string longer than <nLen>, characters are deleted.

The counterpart of the functions PadC(), PadL() and PadR() are the functions Alltrim(), LTrim() and RTrim() which delete leading and/or trailing blank spaces.

PadC() | PadL() | PadR()
// The example shows how values can be formatted 
// with the PAD() functions. 

   LOCAL cString, nNumber, dDate 

   cString := "Xbase++" 
   nNumber := 123.456 
   dDate   := Date() 

   ? PadC( cString, 11, "_" )    // result: __Xbase++__ 
   ? PadL( nNumber, 11, "_" )    // result: ____123.456 
   ? PadR( dDate  , 11, "_" )    // result: 12/06/94___ 

   ? PadC( cString,  5, "_" )    // result: Xbase 
   ? PadL( nNumber,  5, "_" )    // result: 123.4 
   ? PadR( dDate  ,  5, "_" )    // result: 12/06 



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.