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'
  • 相关阅读:
    Configuring the launch of the remote virtual machine to debug
    java LimitedThreadPool
    java并发之SynchronousQueue实现原理
    java 线程池线程忙碌且阻塞队列也满了时给一个拒接的详细报告
    Java程序监控指标
    JDK提供的四种线程池
    Guava的Supplier实现单例
    JMM
    Dubbo源码解读:appendAnnotation [01]
    PCI(Payment Card Industry)合规
  • 原文地址:https://www.cnblogs.com/rxhuiu/p/9112102.html
Copyright © 2011-2022 走看看