1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > RPAD()和LPAD()函数进行字符串的填充

RPAD()和LPAD()函数进行字符串的填充

时间:2020-01-25 21:56:14

相关推荐

RPAD()和LPAD()函数进行字符串的填充

RPAD()函数从右边对字符串使用指定的字符进行填充。

格式:RPAD(string,padded_length,[pad_string])

string 表示:被填充的字符串。

padded_length 表示:字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,rpad函数将会把字符串截取成从左到右的n个字符;

pad_string 是个可选参数,这个字符串是要粘贴到string的右边,如果这个参数未写,lpad函数将会在string的右边粘贴空格。

例如:

1 rpad('tech', 7); 将返回'tech ' 2 rpad('tech', 2); 将返回'te' 3 rpad('tech', 8, '0'); 将返回'tech0000' 4 rpad('tech on the net', 15, 'z'); 将返回 'tech on the net' 5 rpad('tech on the net', 16, 'z'); 将返回 'tech on the netz'

-----------------------------------------------------------------------------------------------------------------------

LPAD()函数将左边的字符串填充一些特定的字符.

格式:LPAD(string,padded_length,[pad_string])

string:被填充的字符串。

padded_length:字符的长度,是返回的字符串的数量,如果这个数量比原字符串的长度要短,lpad函数将会把字符串截取成从左到右的n个字符;

pad_string:是个可选参数,这个字符串是要粘贴到string的左边,如果这个参数未写,lpad函数将会在string的左边粘贴空格。

例如:

1 lpad('tech', 7); 将返回' tech'2 3 lpad('tech', 2); 将返回'te'4 5 lpad('tech', 8, '0'); 将返回'0000tech'6 7 lpad('tech on the net', 15, 'z'); 将返回'tech on the net'8 9 lpad('tech on the net', 16, 'z'); 将返回'ztech on the net'

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。