Next: , Previous: , Up: strings   [Index]


25.11 Padding and trimming

Function: %string-pad requested-len fill-char str start past
Function: %string-pad-right requested-len fill-char str start past
Macro: string-pad S requested-len
Macro: string-pad S requested-len fill-char
Macro: string-pad-right S requested-len
Macro: string-pad-right S requested-len fill-char

Build a string of length requested-len comprised of str padded on the left or right by as many occurrences of the character fill-char as needed. Always return a newly allocated string.

If str has more than requested-len chars, it is truncated on the left or right to length requested-len. For the macros: fill-char defaults to #\space.

Examples:

(string-pad     "325" 5) ⇒ "  325"
(string-pad   "71325" 5) ⇒ "71325"
(string-pad "8871325" 5) ⇒ "71325"
Function: %string-trim char/char-set/pred str start past
Function: %string-trim-right char/char-set/pred str start past
Function: %string-trim-both char/char-set/pred str start past
Macro: string-trim S char/char-set/pred
Macro: string-trim-right S char/char-set/pred
Macro: string-trim-both S char/char-set/pred

Trim str by skipping over all characters on the left/on the right/on both sides that satisfy the second parameter char/char-set/pred:

Always return a newly allocated string.