zoukankan      html  css  js  c++  java
  • 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'
  • 相关阅读:
    Linux_vi编辑器
    Linux_几个符号命令
    Linux_权限
    Linux_用户/用户组
    Linux_文件及文件夹[创建][复制][移动][删除][重命名]
    Linux_文件查看
    Linux_初识
    码农网站
    学习网站
    软件设计师考试范围
  • 原文地址:https://www.cnblogs.com/rxhuiu/p/9112102.html
Copyright © 2011-2022 走看看