This language bar is your friend. Select your favorite languages!

Idiom #215 Pad string on the left

Prepend extra character c at the beginning of string s to make sure its length is at least m.
The length is the number of characters, not the number of bytes.

import "strings"
import "utf8"
if n := utf8.RuneCountInString(s); n < m {
	s = strings.Repeat(c, m-n) + s
}
LazUtf8
s := UTF8PadLeft(s,m,c);
s = s.rjust(m, c)
s.rjust(m, c)

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms