string:right/3
让字符串右对齐
用法:
right(String, Number, Character) -> Right
内部实现:
-spec right(String, Number, Character) -> Right when String :: string(), Right :: string(), Number :: non_neg_integer(), Character :: char(). right(String, Len, Char) when is_integer(Char) -> Slen = length(String), if Slen > Len -> substr(String, Slen-Len+1); Slen r_pad(String, Len-Slen, Char); Slen =:= Len -> String end. r_pad(String, Num, Char) -> chars(Char, Num, String).
返回一个从字符串右边开始,扩充到指定长度 Number 的新字符串,不足则用字符 Character 填充
string:right("1234567890", 20, $a).