left-pad
left-pad
1 Typed Racket API
left-pad
8.12

left-pad🔗ℹ

String left pad

 (require left-pad) package: left-pad

Examples:
> (require left-pad)
> (left-pad "foo" 5)

"  foo"

> (left-pad "foobar" 6)

"foobar"

> (left-pad 17 5 0)

"00017"

procedure

(left-pad value pad-width [pad-value])  string?

  value : any/c
  pad-width : exact-positive-integer?
  pad-value : " " = any/c
Converts value to a string in display mode, then pads it with copies of pad-value (after coercing pad-value to a string) until the result has length pad-width.

Returns the same result as:
(~a value #:align 'right
          #:min-width pad-width
          #:left-pad-string (~a pad-value))
except that it can be faster (or slower — it’s currently slower).

The preconditions of left-pad are:
  • The display-mode representation of value has at most pad-width characters.

  • The display-mode representation of pad-value has exactly 1 character.

The postconditions of left-pad are:
  • Returns a string with pad-width characters.

  • The display-mode representation of value is a suffix of the result string.

  • The result is left-padded with copies of (the display-mode representation of) pad-value.

The pre- and post-conditions are enforced by a badass dependent contract.

1 Typed Racket API🔗ℹ

 (require left-pad/typed) package: left-pad

value

left-pad : (->* [Any Integer] [Any] String)