padleft(X;Y)

Returns the given string with a certain number of characters, adding blanks at the beginning if necessary.

Syntax

padleft(X;Y)

Input

Argument Type Description
X text The string on which to apply the function

A scalar value or the name of a column

Y integer The number of characters of the resultant string

Return Value

Returns the text string from the end of X up to the number of characters specified by Y. If Y is greater than the length of X, blanks are added to the beginning of the resultant string.

If X is N/A, the result is a string consisting of Y blank characters.

Sample Usage

value length padleft(value;length)
'banana' 4 'nana'
'banana' 10 'banana'

Example

In the example for padright(X;Y), we used the "Product Master" table (pub.demo.retail.prod) to demonstrate how we could add padding to the department descriptions to help align the division descriptions in a computed column we created. We used Macro Language similar to the following.

<base table="pub.demo.retail.prod"/>
<willbe name="padright_dept" value="padright(deptdesc;20)"/>
<willbe name="padright_result" label="Department / Division" 
 value="splice(padright_dept divdesc;'/')" format="width:40"/>

which resulted in a column that looked like:

But what if we wanted to add space before the division descriptions so that they appeared right-justified after the slashes ("/"), resulting in a column that looked something like:

FOOTWEAR            /        APPAREL             
SNACKS              /        GROCERY
SNACKS              /        GROCERY
TOOLS/AUTO          /      DRY GOODS
TOOLS/AUTO          /      DRY GOODS

We could use padleft(X;Y) to add padding to the beginning of the division descriptions so that they are all the same length.

For our example, let's make all the division descriptions 15 characters in length. To do this, create a computed column and apply padleft(X;Y) to the divdesc column and specify 15 for the Y parameter:

<willbe name="padleft_divdesc" value="padleft(divdesc;15)"/>

This creates a new column whose division description values are all 15 characters in length, with extra blank spaces added to the beginning of those values that are less than 15 characters:

Note: Though the blank spaces do not appear in the new created column, they are part of the values in that column, which you will see in the following step.

Now, we can create a new computed column using the splice(X;Y) function again, but this time we will specify the new padleft_divdesc column instead of the divdesc column in the list for the X parameter so that we get the padded strings:

<willbe name="padleft_result" label="Department / Division" 
 value="splice(padright_dept padleft_divdesc;'/')" format="width:40"/>
Note: We specify the display format attribute width to <willbe> so that the column width will accommodate the larger string length.

This results in a column that looks like:

Now, each division description is 15 characters in length, following the slash, and is padded on the left with blanks.

Additional Information

  • This function does not work with Unicode (UTF-8) strings.
  • For a Unicode-compliant alternative, consider strembed(X;N;P;Y;D).