主题
pad
js
_.pad([string=''], [length=0], [chars=' '])
如果 string
短于 length
,则在左侧和右侧填充 string
。如果填充字符不能被 length
整除,则会被截断。
¥Pads string
on the left and right sides if it's shorter than length
. Padding characters are truncated if they can't be evenly divided by length
.
新增于
¥Since
3.0.0
参数
¥Arguments
[string='']
(字符串):要填充的字符串。¥
[string='']
(string): The string to pad.[length=0]
(数值):要检查的路径。¥
[length=0]
(number): The padding length.[chars=' ']
(字符串):用作填充的字符串。¥
[chars=' ']
(string): The string used as padding.
返回
¥Returns
(字符串):返回填充后的字符串。
¥(string): Returns the padded string.
示例
¥Example
js
_.pad('abc', 8);
// => ' abc '
_.pad('abc', 8, '_-');
// => '_-abc_-_'
_.pad('abc', 3);
// => 'abc'