工具类之字符串的脱敏操作
作者:互联网
public static String nickNameMasking(String nickName) {
if (null!=nickName) {
int length = nickName.length();
if (length == 1) {
return maskReplce(nickName, 0, 1);
} else if (length == 2) {
return maskReplce(nickName, 1, 2);
} else {
return maskReplce(nickName, 1, length - 1);
}
}
return "*";
}
public static String maskReplce(String str, int start, int end) {
int i = end - start;
StringBuffer maskStr = new StringBuffer();
for (int j = 0; j < i; j++) {
maskStr.append("*");
}
StringBuilder sb = new StringBuilder(str);
sb.replace(start, end, maskStr.toString());
return sb.toString();
}
标签:return,maskReplce,int,length,字符串,工具,nickName,脱敏,String 来源: https://www.cnblogs.com/8ling1ling/p/15304865.html