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;
    }

 

posted @ 2021-10-11 17:26  二次元的程序猿  阅读(725)  评论(0编辑  收藏  举报