xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

PadC() | PadL() | PadR()

Pads values of data type Character, Date and Numeric with a fill character.

Syntax

PadC( <expression>, <nLength>, [<cFillChar>] ) --> cPaddedString
PadL( <expression>, <nLength>, [<cFillChar>] ) --> cPaddedString
PadR( <expression>, <nLength>, [<cFillChar>] ) --> cPaddedString

Arguments

<expression>
An expression yielding a Character, Date or Numeric value.
<nLength>
A numeric value indicating the length of the returned string.
<cFillChar>
A single character used to pad the value of <expression> with. It defaults to a space character (Chr(32)).

Return

The function returns a character string of <nLength> characters. It contains the value of <expression> padded with <cFillChar>. If the value of <expression> contains more than <nLength> characters, the value in the returned string is truncated to <nLength> characters.

Description

PadC(), PadL(), and PadR() are conversion functions that convert the value of an expression to a character string, padded with a fill character. The functions accept for <expression> values of data type Character, Date and Numeric.

PadC() The fill character is added on the left and the right side, so that the value of <expression> appears centered in the result string.

PadL() The fill character is added on the left side, so that the value of <expression> appears right justified in the result string.

PadL() The fill character is added on the right side, so that the value of <expression> appears left justified in the result string.

Note:  function Pad() is a synonym for PadR().

Info

See also:Alltrim(), LTrim(), RTrim(), StrTran(), Stuff(), SubStr()
Category: Character functions , Conversion functions
Source:rtl/pad.c, rtl/padc.c, rtl/padl.c, rtl/padr.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example shows the results of creating padded character strings

   PROCEDURE Main
      ? PadC( "xHarbour", 12, "_" )   // result: __xHarbour__
      ? PadL( "xHarbour", 12, "_" )   // result: ____xHarbour
      ? PadR( "xHarbour", 12, "_" )   // result: xHarbour____

      ? "0x" + PadL( 2, 4, "0" )      // result: 0x0002
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe