安卓姓名脱敏

 Integer RESULT_NAME_LENGTH =2;
    public  String protectedName(String userName){

        userName = userName.trim();
        char[] r = userName.toCharArray();
        String resultName = "";
        if(r.length == RESULT_NAME_LENGTH){
            resultName =  r[0]+"*";
        }
        if (r.length > RESULT_NAME_LENGTH&&r.length < 7) {
            String star = "";
            for (int i = 0; i < r.length-RESULT_NAME_LENGTH; i++) {
                star=star+"*";
            }
            resultName = r[0]+star+r[r.length-1];
        }
        if (r.length > 6) {
            String star = "";
            for (int i = 0; i < 6; i++) {
                star=star+"*";
            }
            resultName = r[0]+star+r[r.length-1];
        }
        return resultName;
    }

你可能感兴趣的:(Android精华教程,android,脱敏,姓名)