lpad left-pads text until it reaches a specified width. It fills the extra space with a chosen character, or with spaces when no character is provided. This makes numeric values and other fields line up cleanly in terminal tables. section 5.1.4 section 5.5
Use lpad to control the visible width of a text field:
- lpad("ABC", 6, '-') returns "---ABC". section 5.1.4
- lpad("16.75", 5) preserves the value while making it suitable for a five-character column; spaces are added only when needed. section 5.1.4
- Pair lpad with rpad when labels and text should align from opposite sides. section 5.1.3
Aligning pizza prices
Inside a pizza-table loop, use lpad(price(pz), 5) for the price column while rpad(name(pz), 12) and rpad(portion(pz), 4) align the other fields. Values such as 10.5 and 20.75 then occupy a consistent five-character column. section 5.1 section 5.1.4
julia> lpad("ABC", 6, '-') #1
"---ABC"
julia> rpad("ABC", 6, '-') #2
"ABC---"
Compare left and right padding directly with runnable REPL expressions. section 5.1.4
