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

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

Syntax
PadL( <Expression>, <nLen>, [<cFillChr>] ) --> cString
PadC( <Expression>, <nLen>, [<cFillChr>] ) --> cString
PadR( <Expression>, <nLen>, [<cFillChr>] ) --> cString
Parameters
<Expression>
<Expression> is an expression having data type character, date or numeric. It is converted to a character string.
<nLen>
<nLen> is a positive integer indicating the length of the character string returned.
<cFillChr>
<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.
Return

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.

Description

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.

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

PROCEDURE Main 
   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 

RETURN 

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.