公司用的-----------在一个字符串前面补指定个数的0或者空格,

来源:互联网 发布:linux误删除网卡文件 编辑:程序博客网 时间:2024/04/30 00:43
package com.rib.icop.util;public class RibStringUtils {        /**     * 将String前补0,补全为指定的位数     * @param src     * @param targetLength     * @return     */    public static String preCompleteWithZero(String src, int targetLength) {        StringBuffer tmp = new StringBuffer();        int currentLength = src.length();        for (int i = 0; i < targetLength - currentLength; i++) {            tmp.append("0");        }        return tmp.append(src).toString();    }        /**     * 将String前补空格,补全为指定的位数     * @param src     * @param targetLength     * @return     */    public static String postCompleteWithBlank(String src, int targetLength) {        StringBuffer tmp = new StringBuffer();        tmp.append(src);        int currentLength = src.length();        for (int i = 0; i < targetLength - currentLength; i++) {            tmp.append(" ");        }        return tmp.toString();    }}

0 0
原创粉丝点击