rpad right-pads a string until it reaches a requested length. Supply a padding character such as '-' or let it default to spaces; the result is useful for readable text columns. section 5.1.4 section 5.5
Use rpad when formatting output:
- rpad("ABC", 6, '-') returns "ABC---". section 5.1.4
- rpad("name", 12) reserves a twelve-character name column and fills unused width with spaces. section 5.1.4
- Combine rpad with lpad when labels align on the left but numeric values align on the right. section 5.1
Aligning a pizza table
A compact table can assign fixed widths to its headings and values: pname = rpad("name", 12), psize = rpad("size", 4), and pprice = lpad(price(pz), 5). Names and sizes then occupy consistent columns while prices line up at the right edge. section 5.1 section 5.1.4
Inspect a formatted pizza-sales display to see the practical result of aligned text columns and styled terminal output. section 5.0
