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

 

上一篇:力扣1044.Longest Duplicate Substring C++ Accepted


下一篇:mysql截取字符串的四种方式