package com.yihu.wlyy.util;

public class MyStringUtil {
	  /**
     * 根据用户名的不同长度，来进行替换 ，达到保密效果
     *
     * @param userName 用户名
     * @return 替换后的用户名
     */
    public static String userNameReplaceWithStar(String userName) {
        String userNameAfterReplaced = "";

        if (userName == null){
            userName = "";
        }

        int nameLength = userName.length();

        if (nameLength <= 1) {
            userNameAfterReplaced = "*";
        } else if (nameLength == 2) {
            userNameAfterReplaced = userName.substring(0, 1)+"*";
        } else  {
            userNameAfterReplaced = userName.substring(0, 1)+"*"+userName.substring(userName.length()-1,userName.length());
        } 

        return userNameAfterReplaced;

    }
    

    /**
     * 实际替换动作
     *
     * @param username username
     * @param regular  正则
     * @return
     */
    private static String replaceAction(String username) {
        return username.replaceAll("(\\d{3})(\\d{5})(\\d{3})", username);
    }

}
