String num = "13520096531"; String s1 = StringUtils.right(num, 4); System.out.println(s1); String s2 = StringUtils.leftPad(s1, StringUtils.length(num), "*"); System.out.println(s2); String s3 = StringUtils.removeStart(s2,"***"); System.out.println(s3); String s4 = StringUtils.left(num, 3).concat(s3); System.out.println(s4); //System.out.println(StringUtils.left(num, 3).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(num, 4), StringUtils.length(num), "*"), "***"))); String num1 = "13520096531"; String d1 = StringUtils.right(num1, 4); String d2 = StringUtils.center(d1, 11, "*"); System.out.println(d2);
控制台输出:
6531 *******6531 ****6531 135****6531 ***6531****