rpad(string, n, p)

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


In the Julia programming language, the function rpad(string, n, p) is used to create a string that is at least n columns wide when printed. It achieves this by padding the string on the right with copies of p. Here are some examples of how it can be used:

  1. Pad a string with spaces:

    julia> rpad("hello", 10, ' ')
    "hello     "

    This example pads the string "hello" with spaces on the right until it becomes at least 10 columns wide.

  2. Pad a string with a specific character:

    julia> rpad("hello", 8, '-')

    It pads the string "hello" with hyphens until it becomes at least 8 columns wide.

  3. Handle cases where the string is already wider than n:
    julia> rpad("hello", 4, '*')

    In this case, the original string "hello" is already wider than the desired width of 4 columns, so no padding is added.

Common mistake example:

julia> rpad("hello", -5, ' ')
ERROR: DomainError with -5:
Negative widths are not allowed for rpad!.

Here, a negative width is provided, which is not allowed for rpad. Make sure to provide a positive value for n to avoid this error.

Remember to provide a valid character for padding (p) and ensure that the resulting string is not wider than the desired width (n).

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: