lpad(string, n, p)

Make a string at least n columns wide when printed, by padding on the left with copies of p.


julia> lpad("Julia", 10, "*")

julia> lpad("25", 5, "0")

julia> lpad("Hello, World!", 15, "-")
"Hello, World!"

julia> lpad("Julia", 3, "*")
  • The first example pads the string "Julia" with five asterisks on the left to make it at least 10 columns wide.
  • The second example pads the string "25" with three zeroes on the left to make it at least 5 columns wide.
  • The third example doesn't require any padding since the string "Hello, World!" is already wider than 15 columns.
  • The fourth example doesn't perform any padding since the string "Julia" is already wider than 3 columns.

Common mistake example:

julia> lpad("Julia", -5, "*")
ERROR: DomainError with -5:
Padding width must be non-negative

In this example, a negative padding width -5 is provided, which results in a DomainError. The padding width must be a non-negative value. Always ensure that the padding width is a valid input to avoid such errors.

See Also

ascii, base64decode, Base64DecodePipe, base64encode, Base64EncodePipe, bin, bits, bytestring, charwidth, chomp, chop, chr2ind, contains, endswith, escape_string, graphemes, ind2chr, iscntrl, istext, isupper, isvalid, join, lcfirst, lowercase, lpad, lstrip, normalize_string, num2hex, parseip, randstring, readuntil, replace, repr, rpad, rsplit, rstrip, search, searchindex, split, startswith, string, stringmime, strip, strwidth, summary, takebuf_string, ucfirst, unescape_string, uppercase, utf16, utf32, utf8, wstring,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: