string:chars/2
返回包含指定数目个字符的字符串
用法:
chars(Character, Number) -> String
内部实现:
-spec chars(Character, Number) -> String when Character :: char(), Number :: non_neg_integer(), String :: string(). chars(C, N) -> chars(C, N, []). -spec chars(Character, Number, Tail) -> String when Character :: char(), Number :: non_neg_integer(), Tail :: string(), String :: string(). chars(C, N, Tail) when N > 0 -> chars(C, N-1, [C|Tail]); chars(C, 0, Tail) when is_integer(C) -> Tail.
返回包含 Number 个字符 Character 的字符串 String
string:chars($a, 5).