Gallery
LeftPad and RightPad
Share
Explore

icon picker
LeftPad and RightPad

Formula: LeftPad() , RightPad()
Category: String
double-left.svg
LeftPad()
Pads text from the left
It’s kind of like saying...
Hey Coda, will you add extra values to the left of this text?
double-right.svg
RightPad()
Pads text from the right
Or put another way...
Hey Coda, will you add extra values to the right of this text?

LeftPad() and RightPad() take three parameters. Two are required and one is optional:
Required
text-color (3).svg
Text

PadLeft(Text, TargetLength, PadString)

The value that you want to pad.

Required
height (1).svg
TargetLength

PadLeft(Text, TargetLength, PadString)

The length of the value after it's padded.
Optional
energy-absorber (1).svg
PadString

PadLeft(Text, TargetLength, PadString)

The text to pad your values with.


Both formulas pad or add extra characters to a string if that string is not the desired length. This formula is best learned within an example.
A consulting business sends out invoices to their clients. For the sake of consistency, they want their invoice numbers to always be the same number of characters in length. LeftPad() and RightPad() allow this consulting firm to ensure that every invoice stays consistent.
Play with the invoice creator below to see how this formula works. No matter how big you make the invoice number, it will alway be 5 characters long.
Invoice number:
00000
0
Pad String with:
Invoice should be
0
0
characters long

Invoice #
0
Cost: $5000

Done
Create anonymous and uniform identification numbers for people
Done
Done

Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.