Hey Coda, will you add extra values to the left of this text?
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
PadLeft(Text, TargetLength, PadString)
The value that you want to pad.
Required
TargetLength
PadLeft(Text, TargetLength, PadString)
The length of the value after it's padded.
Optional
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
Practice: Make a 3 digit number 5 digits long
Done
Create anonymous and uniform identification numbers for people
Done
Challenge: Fill out and anonymize social security numbers