name* until

package com.cxqy.community.util;
/**
* @Author yjl
* @Date 2021/4/9 15:45
* @Version 1.0
*/



public class InterceptNameUtil {


/**
* 所有常量
*/
public static final String EMPTY = "";
public static final int ZERO = 0;
public static final int ONE = 1;
public static final int TWO = 2;
public static final int THREE = 3;
public static final int FOUR = 4;
public static final int FIVE = 5;
public static final int SIX = 6;
public static final int SEVEN = 7;
public static final int EIGHT = 8;
public static final int NINE = 9;

public static String left(String str, int len) {
if (str == null) {
return null;
}

str = removeEmoji(str);



if (len < ZERO) {
return EMPTY;
}
if (str.length() <= len) {
return str;
}
return str.substring(ZERO, len);

}

public static String right(String str, int len) {
if (str == null) {
return null;
}
if (len < ZERO) {
return EMPTY;
}
if (str.length() <= len) {
return str;
}
return str.substring(str.length() - len);

}
public static String checkNameLength(String str){
if(str == null){
return null;
}
if(str.length() == ONE) {
return str;
}else if(str.length() == TWO){
return "*" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == THREE){
return InterceptNameUtil.left(str, ONE) + "*" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == FOUR){
return InterceptNameUtil.left(str, ONE) + "**" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == FIVE){
return InterceptNameUtil.left(str, ONE) + "**" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == SIX){
return InterceptNameUtil.left(str, ONE) + "**" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == SEVEN){
return InterceptNameUtil.left(str, ONE) + "**" + InterceptNameUtil.right(str, ONE);
}else if(str.length() == EIGHT){
return InterceptNameUtil.left(str, ONE) + "**" + InterceptNameUtil.right(str, ONE);
}else if(str.length() > NINE){
return InterceptNameUtil.left(str, ONE) + "***" + InterceptNameUtil.right(str, ONE);
}

return str;
}

public static String removeEmoji(String alias){
String source=new String (alias);
while(true) {
Integer pos = source.indexOf("uD83D");
if(pos == -1) {
pos = source.indexOf("uD83C");
}
if(pos != -1) {
source = source.substring(0, pos) + source.substring(pos +2);
}else{
break;
}
}
return source;

}


}
原文地址:https://www.cnblogs.com/yangsanluo/p/14637821.html