编程语言
首页 > 编程语言> > java处理银行卡号格式(每四位添加空格)

java处理银行卡号格式(每四位添加空格)

作者:互联网

/**
     * desc: 处理银行卡号格式
     * @param bankCardNum
     * @return {@link String}
    */
    private String handleBankCardNum(String bankCardNum) {
        String bankCardStr = "";
        if (StringUtil.isNotBlank(bankCardNum)) {
            bankCardStr = handleBankCard(bankCardNum);
        }
        return bankCardStr;
    }

    private String handleBankCard(String bankCardNum) {
        String str = "";
        if (StringUtil.isNotBlank(bankCardNum)) {
            if (bankCardNum.length() >= 4) {
                str = bankCardNum.substring(0, 4) + " ";
                String substring = bankCardNum.substring(4);
                str += handleBankCard(substring);
            } else {
                str += bankCardNum;
            }
        }
        return str;
    }

 

标签:substring,bankCardStr,java,String,空格,str,return,四位,bankCardNum
来源: https://www.cnblogs.com/stromgao/p/15394257.html