zoukankan      html  css  js  c++  java
  • 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;

    }


    }
  • 相关阅读:
    图标工具箱
    第40课 程序的内存布局
    第39课 程序中的三国天下
    第38课 动态内存分配
    第37课 指针阅读技巧分析
    第36课 函数与指针分析
    第35课 数组参数和指针参数分析
    第34课 多维数组和多维指针
    第33课 main函数与命令行参数
    第32课 数组指针和指针数组分析
  • 原文地址:https://www.cnblogs.com/yangsanluo/p/14637821.html
Copyright © 2011-2022 走看看