package com.xwkj.jcjcgz.app.utils;

import android.text.TextUtils;

public class StringUtil {

    /**
     * 保留前二后二，其他替换为*
     * @param id
     * @return
     */
    public static String replaceId(String id) {
        if (TextUtils.isEmpty(id) || id.length() != 18) {
            return id;
        }
        return id.replaceAll("(?<=[\\w]{2})\\w(?=[\\w]{2})", "*");
    }

    /**
     *
     * @param str
     * @return
     */
    public static String replaceString(String str) {
        if (TextUtils.isEmpty(str) || str.length() < 6) {
            return str;
        }
        int length = str.length();
        if (length >= 6 && length < 11) {
            return str.replaceAll("(?<=[\\w]{2})\\w(?=[\\w]{2})", "*");
        }
        return str.replaceAll("(?<=[\\w]{2})\\w(?=[\\w]{2})", "*");
    }

}
