Logo

Programming-Idioms

Append extra character c at the end of string s to make sure its length is at least m.
The length is the number of characters, not the number of bytes.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
s = s.PadRight(m, c);
s = s.padRight(m, c);
That's automatically the way strings are handled, as specified by the Fortran language standard.
CHARACTER(N) ::  FOO
import "strings"
import "utf8"
if n := utf8.RuneCountInString(s); n < m {
	s += strings.Repeat(c, m-n)
}
s = s.padEnd(m, c);
uses LazUtf8;
s := UTF8PadRight(s,m,c);
$s = length($s) >= $m ? $s : $s . $c x ( $m-length($s) );
$s .= $c x ($m - length $s)
s = s.ljust(m, c)
s = s.ljust(m, c)
use pad::PadStr;
let out = s.pad_to_width_with_char(m, c);