PADEND


Appends a character to the text until it reaches a length of count.

Syntax:

PADEND(text, count, character)


text is the text that we want to add padding to.


count is how long you want the new value to be.


character is optional, default is a space if no character is specified, otherwise PADEND will use the specified character.


Example:

If text contains Hello, count contains 12 and no specified character:

PADEND("Hello", 12)

returns "Hello       "


If text contains Hello, count contains 12 and character contains !:

PADEND("Hello", 12, "!")

returns "Hello!!!!!!!"


Text:


Count:


Character:


Result:

Hello!!!!!!!

Application:

Imagine you are generating a daily sales report for a company. This report needs to be a fixed-width text file so that it can be easily parsed by another system. The format requires the "Product Name" column to be 20 characters long and the "Price" column to be 10 characters long, both padded with spaces.


Here is a table showing the raw data and the desired output after applying PADEND:

Raw Data

Product

Price

A
B
1
Laptop
1200.50
2
Mouse
25.00
3
Keyboard
75.75
4
Monitor
350.00

Applying PADEND

To achieve the desired fixed-width output, we would apply PADEND to each column.

  • PADEND(Product, 20, "-")
  • PADEND(Price, 10, "-")


Fixed-Width Report Output

Product

Price

Product Name (20 chars)

Price (10 chars)

A
B
C
D
1
Laptop
1200.50
Laptop--------------
1200.50---
2
Mouse
25.00
Mouse---------------
25.00-----
3
Keyboard
75.75
Keyboard------------
75.75-----
4
Monitor
350.00
Monitor-------------
350.00----

The PADEND function ensures that each entry in the "Product Name" column is exactly 20 characters long by appending "-" to the end. Similarly, it ensures each "Price" entry is exactly 10 characters long. This results in a clean, consistent, and easily parsable report format, where each field starts at a predictable position.





This page is protected by Google reCAPTCHA. Privacy - Terms.
 
Built using Zapof