高频方法集合类

ToolUtil

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jyzx.jyzs.core.support.StrKit;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.net.URISyntaxException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 高频方法集合类
 */
public class ToolUtil {

    /**
     * 获取随机位数的字符串
     *
     * @author 
     * @Date 
     */
    public static String getRandomString(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    /**
     * 时间比较函数
     *
     * @param nowTime
     * @param startTime
     * @param endTime
     * @return
     */
    public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return true;
        }
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);
        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);
        Calendar end = Calendar.getInstance();
        end.setTime(endTime);
//        System.out.println("time==" + nowTime+"time==" +startTime+"time==" +endTime);
//        System.out.println("date.after==" + date.after(begin));
//        System.out.println("date.before==" +date.before(end));
        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 判断一个对象是否是时间类型
     *
     * @author 
     * @Date 
     */
    public static String dateType(Object o) {
        if (o instanceof Date) {
            return DateUtil.getTime((Date) o);
        } else {
            return o.toString();
        }
    }

    /**
     * 获取异常的具体信息
     *
     * @author 
     * @Date 
     * @version 2.0
     */
    public static String getExceptionMsg(Exception e) {
        StringWriter sw = new StringWriter();
        try {
            e.printStackTrace(new PrintWriter(sw));
        } finally {
            try {
                sw.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return sw.getBuffer().toString().replaceAll("\\$", "T");
    }

    /**
     * 比较两个对象是否相等。<br>
     * 相同的条件有两个,满足其一即可:<br>
     * 1. obj1 == null && obj2 == null; 2. obj1.equals(obj2)
     *
     * @param obj1 对象1
     * @param obj2 对象2
     * @return 是否相等
     */
    public static boolean equals(Object obj1, Object obj2) {
        return (obj1 != null) ? (obj1.equals(obj2)) : (obj2 == null);
    }

    /**
     * 计算对象长度,如果是字符串调用其length函数,集合类调用其size函数,数组调用其length属性,其他可遍历对象遍历计算长度
     *
     * @param obj 被计算长度的对象
     * @return 长度
     */
    public static int length(Object obj) {
        if (obj == null) {
            return 0;
        }
        if (obj instanceof CharSequence) {
            return ((CharSequence) obj).length();
        }
        if (obj instanceof Collection) {
            return ((Collection<?>) obj).size();
        }
        if (obj instanceof Map) {
            return ((Map<?, ?>) obj).size();
        }

        int count;
        if (obj instanceof Iterator) {
            Iterator<?> iter = (Iterator<?>) obj;
            count = 0;
            while (iter.hasNext()) {
                count++;
                iter.next();
            }
            return count;
        }
        if (obj instanceof Enumeration) {
            Enumeration<?> enumeration = (Enumeration<?>) obj;
            count = 0;
            while (enumeration.hasMoreElements()) {
                count++;
                enumeration.nextElement();
            }
            return count;
        }
        if (obj.getClass().isArray() == true) {
            return Array.getLength(obj);
        }
        return -1;
    }

    /**
     * 对象中是否包含元素
     *
     * @param obj     对象
     * @param element 元素
     * @return 是否包含
     */
    public static boolean contains(Object obj, Object element) {
        if (obj == null) {
            return false;
        }
        if (obj instanceof String) {
            if (element == null) {
                return false;
            }
            return ((String) obj).contains(element.toString());
        }
        if (obj instanceof Collection) {
            return ((Collection<?>) obj).contains(element);
        }
        if (obj instanceof Map) {
            return ((Map<?, ?>) obj).values().contains(element);
        }

        if (obj instanceof Iterator) {
            Iterator<?> iter = (Iterator<?>) obj;
            while (iter.hasNext()) {
                Object o = iter.next();
                if (equals(o, element)) {
                    return true;
                }
            }
            return false;
        }
        if (obj instanceof Enumeration) {
            Enumeration<?> enumeration = (Enumeration<?>) obj;
            while (enumeration.hasMoreElements()) {
                Object o = enumeration.nextElement();
                if (equals(o, element)) {
                    return true;
                }
            }
            return false;
        }
        if (obj.getClass().isArray() == true) {
            int len = Array.getLength(obj);
            for (int i = 0; i < len; i++) {
                Object o = Array.get(obj, i);
                if (equals(o, element)) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 对象是否不为空(新增)
     *
     * @param o String,List,Map,Object[],int[],long[]
     * @return
     */
    public static boolean isNotEmpty(Object o) {
        return !isEmpty(o);
    }

    /**
     * 对象是否为空
     *
     * @param o String,List,Map,Object[],int[],long[]
     * @return
     */
    @SuppressWarnings("rawtypes")
    public static boolean isEmpty(Object o) {
        if (o == null) {
            return true;
        }
        if (o instanceof String) {
            return o.toString().trim().equals("");
        } else if (o instanceof List) {
            return ((List) o).size() == 0;
        } else if (o instanceof Map) {
            return ((Map) o).size() == 0;
        } else if (o instanceof Set) {
            return ((Set) o).size() == 0;
        } else if (o instanceof Object[]) {
            return ((Object[]) o).length == 0;
        } else if (o instanceof int[]) {
            return ((int[]) o).length == 0;
        } else if (o instanceof long[]) {
            return ((long[]) o).length == 0;
        }
        return false;
    }

    /**
     * 格式化价格显示
     *
     * @param price - 价格,单位分
     * @return 价格, 单位元
     */
    public static String formatCNY(Long price) {
        if (price == null) {
            return "";
        }
        double result = Double.valueOf(price) / 100;
        if (price % 100 == 0) {
            DecimalFormat df = new DecimalFormat("#");
            return df.format(result);
        } else if (price % 10 == 0) {
            DecimalFormat df = new DecimalFormat("0.0");
            return df.format(result);
        } else {
            DecimalFormat df = new DecimalFormat("0.00");
            return df.format(result);
        }
    }

    /**
     * 对象组中是否存在 Empty Object
     *
     * @param os 对象组
     * @return
     */
    public static boolean isOneEmpty(Object... os) {
        for (Object o : os) {
            if (isEmpty(o)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 对象组中是否全是 Empty Object
     *
     * @param os
     * @return
     */
    public static boolean isAllEmpty(Object... os) {
        for (Object o : os) {
            if (!isEmpty(o)) {
                return false;
            }
        }
        return true;
    }

    /**
     * 是否为数字
     *
     * @param obj
     * @return
     */
    public static boolean isNum(Object obj) {
        try {
            Integer.parseInt(obj.toString());
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    /**
     * 如果为空, 则调用默认值
     *
     * @param str
     * @return
     */
    public static Object getValue(Object str, Object defaultValue) {
        if (isEmpty(str)) {
            return defaultValue;
        }
        return str;
    }

    /**
     * 格式化文本
     *
     * @param template 文本模板,被替换的部分用 {} 表示
     * @param values   参数值
     * @return 格式化后的文本
     */
    public static String format(String template, Object... values) {
        return StrKit.format(template, values);
    }

    /**
     * 格式化文本
     *
     * @param template 文本模板,被替换的部分用 {key} 表示
     * @param map      参数值对
     * @return 格式化后的文本
     */
    public static String format(String template, Map<?, ?> map) {
        return StrKit.format(template, map);
    }

    /**
     * 强转->string,并去掉多余空格
     *
     * @param str
     * @return
     */
    public static String toStr(Object str) {
        return toStr(str, "");
    }

    /**
     * 强转->string,并去掉多余空格
     *
     * @param str
     * @param defaultValue
     * @return
     */
    public static String toStr(Object str, String defaultValue) {
        if (null == str) {
            return defaultValue;
        }
        return str.toString().trim();
    }

    /**
     * 强转->int
     *
     * @param obj
     * @return
     */
//	public static int toInt(Object value) {
//		return toInt(value, -1);
//	}

    /**
     * 强转->int
     *
     * @param obj
     * @param defaultValue
     * @return
     */
//	public static int toInt(Object value, int defaultValue) {
//		return Convert.toInt(value, defaultValue);
//	}

    /**
     * 强转->long
     *
     * @param obj
     * @return
     */
//	public static long toLong(Object value) {
//		return toLong(value, -1);
//	}

    /**
     * 强转->long
     *
     * @param obj
     * @param defaultValue
     * @return
     */
//	public static long toLong(Object value, long defaultValue) {
//		return Convert.toLong(value, defaultValue);
//	}
//
//	public static String encodeUrl(String url) {
//		return URLKit.encode(url, CharsetKit.UTF_8);
//	}
//
//	public static String decodeUrl(String url) {
//		return URLKit.decode(url, CharsetKit.UTF_8);
//	}

    /**
     * map的key转为小写
     *
     * @param map
     * @return Map<String, Object>
     */
    public static Map<String, Object> caseInsensitiveMap(Map<String, Object> map) {
        Map<String, Object> tempMap = new HashMap<>();
        for (String key : map.keySet()) {
            tempMap.put(key.toLowerCase(), map.get(key));
        }
        return tempMap;
    }

    /**
     * 获取map中第一个数据值
     *
     * @param <K> Key的类型
     * @param <V> Value的类型
     * @param map 数据源
     * @return 返回的值
     */
    public static <K, V> V getFirstOrNull(Map<K, V> map) {
        V obj = null;
        for (Entry<K, V> entry : map.entrySet()) {
            obj = entry.getValue();
            if (obj != null) {
                break;
            }
        }
        return obj;
    }

    /**
     * 创建StringBuilder对象
     *
     * @return StringBuilder对象
     */
    public static StringBuilder builder(String... strs) {
        final StringBuilder sb = new StringBuilder();
        for (String str : strs) {
            sb.append(str);
        }
        return sb;
    }

    /**
     * 创建StringBuilder对象
     *
     * @return StringBuilder对象
     */
    public static void builder(StringBuilder sb, String... strs) {
        for (String str : strs) {
            sb.append(str);
        }
    }

    /**
     * 去掉指定后缀
     *
     * @param str    字符串
     * @param suffix 后缀
     * @return 切掉后的字符串,若后缀不是 suffix, 返回原字符串
     */
    public static String removeSuffix(String str, String suffix) {
        if (isEmpty(str) || isEmpty(suffix)) {
            return str;
        }

        if (str.endsWith(suffix)) {
            return str.substring(0, str.length() - suffix.length());
        }
        return str;
    }

    /**
     * 当前时间
     *
     * @author 
     * @Date 
     */
    public static String currentTime() {
        return DateUtil.getTime();
    }

    /**
     * 首字母大写
     *
     * @author 
     * @Date 
     */
    public static String firstLetterToUpper(String val) {
        return StrKit.firstCharToUpperCase(val);
    }

    /**
     * 首字母小写
     *
     * @author 
     * @Date 
     */
    public static String firstLetterToLower(String val) {
        return StrKit.firstCharToLowerCase(val);
    }

    /**
     * 判断是否是windows操作系统
     *
     * @author 
     * @Date 
     */
    public static Boolean isWinOs() {
        String os = System.getProperty("os.name");
        return os.toLowerCase().startsWith("win");
    }

    /**
     * 获取临时目录
     *
     * @author 
     * @Date 
     */
    public static String getTempPath() {
        return System.getProperty("java.io.tmpdir");
    }

    /**
     * 把一个数转化为int
     *
     * @author 
     * @Date 
     */
    public static Integer toInt(Object val) {
        if (val instanceof Double) {
            BigDecimal bigDecimal = new BigDecimal((Double) val);
            return bigDecimal.intValue();
        } else {
            return Integer.valueOf(val.toString());
        }

    }

    /**
     * 获取项目路径
     */
    public static String getWebRootPath(String filePath) {
        try {
            String path = ToolUtil.class.getClassLoader().getResource("").toURI().getPath();
            path = path.replace("/WEB-INF/classes/", "");
            path = path.replace("/target/classes/", "");
            path = path.replace("file:/", "");
            if (ToolUtil.isEmpty(filePath)) {
                return path;
            } else {
                return path + "/" + filePath;
            }
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 隐藏银行卡中间的位数
     *
     * @param bankCardNum
     * @return
     */
    public static String getHideBankCardNum(String bankCardNum) {
        try {
            if (bankCardNum == null) return "未绑定";

            int length = bankCardNum.length();

            if (length > 4) {
                String startNum = bankCardNum.substring(0, 3);
                String endNum = bankCardNum.substring(length - 4, length);
                bankCardNum = startNum + " **** " + endNum;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bankCardNum;
    }


    /**
     * 从url中匹配虚拟目录(除去协议、域名、端口号和参数部分)
     *
     * @param url
     * @param containProjectName 是否去掉项目名
     * @return
     */
    public static String getURI(String url, boolean containProjectName) {
        String regx = "(?:https?://)(?:(?:\\w+\\.){2,3}|[a-zA-Z0-9]+)(?:\\w+)(?::[0-9]+)?" + (containProjectName ? "(?:/\\w+/)" : "")
                + "([^?]*)";
        Pattern p = Pattern.compile(regx);
        Matcher matcher = p.matcher(url);
        if (matcher.find()) {
            return matcher.group(1);
        }
        return null;
    }

    /**
     * 匹配域名
     * 如url为http://192.168.10.36:2829/appweb/script/plugin/ueditor/jsp/upload1/20170901/41281504250668218.jpg
     * 返回192.168.10.36
     *
     * @param url
     * @return
     */
    public static String getHost(String url) {
        Pattern p = Pattern.compile("(?:https?://)((\\w+\\.){2,3}\\w+|[a-zA-z0-9]+)(?::[0-9]+)?");
        Matcher matcher = p.matcher(url);
        if (matcher.find()) {
            return matcher.group(1);
        }
        return null;
    }

    //是否为手机号
    public static boolean isPhone(String phone) {
        String PHONE_PATTERN = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17([0,1,6,7,]))|(18[0-2,5-9]))\\d{8}$";
        boolean isPhone = Pattern.compile(PHONE_PATTERN).matcher(phone).matches();
        return isPhone;
    }
    // 通配校验+86或1开头的手机号
    public static boolean wildcardPhone(String phone) {
        String PHONE_PATTERN = "^(1|\\+861)(([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$";
        boolean isPhone = Pattern.compile(PHONE_PATTERN).matcher(phone).matches();
        return isPhone;
    }

    /**
     * 读取文件内容到字节流里
     *
     * @param file
     * @return
     * @throws IOException
     */
    public static byte[] getByteByFile(MultipartFile file) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] buf = new byte[1024 * 24];
        InputStream fileInStr = file.getInputStream();
        int a = 0;
        while (-1 != (a = fileInStr.read(buf))) {
            output.write(buf, 0, a);
        }
        return output.toByteArray();
    }

    /**
     * 只提供给图片格式解析!!!
     * 前端用
     *
     * @param data
     * @return
     */
    public static Object toArray(String data) {
        ArrayList<Object> res = new ArrayList<>();
        if (isEmpty(data)) {
            return res;
        }

        try {
            Object obj = JSONObject.parse(data);
            if (obj instanceof JSONArray) {
                return obj;
            } else {
                res.add(obj);
                return res;
            }
        } catch (Exception e) {
            // 异常的话, 按照字符串处理
            JSONObject m = new JSONObject();
            res.clear();
            m.put("src", data);
            m.put("request_id", UUID.randomUUID().toString());
            m.put("width", 0);
            m.put("height", 0);
            m.put("title", "title");
            res.add(m);
            return res;
        }
    }

    /**
     * g给前端模板解析多选使用(checkbox)
     *
     * @param strArray
     * @return
     */
    public static boolean isInCheckBox(String strArray, String str) {
        if (ToolUtil.isEmpty(strArray)) {
            return false;
        } else {
            List<String> result = Arrays.asList(strArray.split(","));
            for (String strs : result) {
                if (strs.contains(str)) {
                    return true;
                }
            }
            return false;
        }

    }

    /**
     * 前端模板时间转成格式
     *
     * @param date
     * @return
     */
    public static String getDateStyle(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s = sdf.format(date);
        return s;

    }

    public static Object toImage(String data) {
        try {
            return JSONObject.parse(data);
        } catch (Exception e) {
            // 异常的话, 按照字符串处理
            JSONObject m = new JSONObject();
            m.put("src", data);
            m.put("request_id", UUID.randomUUID().toString());
            m.put("width", 0);
            m.put("height", 0);
            m.put("title", "title");
            return m;
        }
    }


    /**
     * 判断字符串中是否含有表情
     *
     * @param source
     * @return
     */
    public static boolean containsEmoji(String source) {
        int len = source.length();
        boolean isEmoji = false;
        for (int i = 0; i < len; i++) {
            char hs = source.charAt(i);
            if (0xd800 <= hs && hs <= 0xdbff) {
                if (source.length() > 1) {
                    char ls = source.charAt(i + 1);
                    int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
                    if (0x1d000 <= uc && uc <= 0x1f77f) {
                        return true;
                    }
                }
            } else {
                // non surrogate
                if (0x2100 <= hs && hs <= 0x27ff && hs != 0x263b) {
                    return true;
                } else if (0x2B05 <= hs && hs <= 0x2b07) {
                    return true;
                } else if (0x2934 <= hs && hs <= 0x2935) {
                    return true;
                } else if (0x3297 <= hs && hs <= 0x3299) {
                    return true;
                } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d
                        || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c
                        || hs == 0x2b1b || hs == 0x2b50 || hs == 0x231a) {
                    return true;
                }
                if (!isEmoji && source.length() > 1 && i < source.length() - 1) {
                    char ls = source.charAt(i + 1);
                    if (ls == 0x20e3) {
                        return true;
                    }
                }
            }
        }
        return isEmoji;
    }

    /**
     * 过滤掉字符串中的表情
     *
     * @param source
     * @return
     */
    public static String filterEmoji(String source) {
        if (StringUtils.isBlank(source)) {
            return source;
        }
        StringBuilder buf = null;
        int len = source.length();
        for (int i = 0; i < len; i++) {
            char codePoint = source.charAt(i);
            if (isEmojiCharacter(codePoint)) {
                if (buf == null) {
                    buf = new StringBuilder(source.length());
                }
                buf.append(codePoint);
            }
        }
        if (buf == null) {
            return source;
        } else {
            if (buf.length() == len) {
                buf = null;
                return source;
            } else {
                return buf.toString();
            }
        }
    }


    /**
     * 判断某个字符是不是表情
     *
     * @param codePoint
     * @return
     */
    private static boolean isEmojiCharacter(char codePoint) {
        return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA)
                || (codePoint == 0xD)
                || ((codePoint >= 0x20) && (codePoint <= 0xD7FF))
                || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD))
                || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF));
    }
    /**
     * 获取随机位数(数字组成)的字符串
     *
     * @param  str:数组   length:长度
     * @return
     */
    public static String getNumberString(String str, int length) {
        char[] c = str.toCharArray();
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            char cc = c[random.nextInt(c.length)];
            sb.append(cc);
        }
        return sb.toString();
    }


    /**
     * 随机生成手机号
     * @return
     */
    public static String getPhoneNum() {
        //给予真实的初始号段,号段是在百度上面查找的真实号段
        String[] start = {"133", "149", "153", "173", "177",

                "180", "181", "189", "199", "130", "131", "132",

                "145", "155", "156", "166", "171", "175", "176", "185", "186", "166", "134", "135",

                "136", "137", "138", "139", "147", "150", "151", "152", "157", "158", "159", "172",

                "178", "182", "183", "184", "187", "188", "198", "170", "171"};

        //随机出真实号段 使用数组的length属性,获得数组长度,

        //通过Math.random()*数组长度获得数组下标,从而随机出前三位的号段

        String phoneFirstNum = start[(int) (Math.random() * start.length)];

        //随机出剩下的8位数

        String phoneLastNum = "";

        //定义尾号,尾号是8位

        final int LENPHONE = 8;

        //循环剩下的位数

        for (int i = 0; i < LENPHONE; i++) {
            //每次循环都从0~9挑选一个随机数

            phoneLastNum += (int) (Math.random() * 10);

        }

        //最终将号段和尾数连接起来

        String phoneNum = phoneFirstNum + phoneLastNum;

        System.out.println(phoneNum);
        return phoneNum;

    }


    /**
     * 判断字符串是否是中文
     */

    private final static int[] areaCode = { 1601, 1637, 1833, 2078, 2274,

            2302, 2433, 2594, 2787, 3106, 3212, 3472, 3635, 3722, 3730, 3858,

            4027, 4086, 4390, 4558, 4684, 4925, 5249, 5590 };

    private final static String[] letters ={
            "A", "B", "C", "D", "E", "F", "G", "H",
            "J", "K", "L", "M", "N", "O", "P", "Q", "R",
            "S", "T", "W", "X", "Y", "Z" };

    public static String getFirstLetter(String chinese) {
        if (chinese == null || chinese.trim().length() == 0) {
            return "";

        }

        chinese = conversionStr(chinese, "GB2312", "ISO8859-1");

        if (chinese.length() > 1) // 判断是不是汉字

        {
            int li_SectorCode = (int) chinese.charAt(0); // 汉字区码

            int li_PositionCode = (int) chinese.charAt(1); // 汉字位码

            li_SectorCode = li_SectorCode - 160;

            li_PositionCode = li_PositionCode - 160;

            int li_SecPosCode = li_SectorCode * 100 + li_PositionCode; // 汉字区位码

            if (li_SecPosCode > 1600 && li_SecPosCode < 5590) {
                for (int i = 0; i < 23; i++) {
                    if (li_SecPosCode >= areaCode[i]

                            && li_SecPosCode < areaCode[i + 1]) {
                        chinese = letters[i];
                        break;
                    }

                }

            } else // 非汉字字符,如图形符号或ASCII码

            {
                chinese = getChinese(chinese);

            }

        }else {
            chinese = getChinese(chinese);
        }

        return chinese;

    }

    private static String conversionStr(String str, String charsetName,String toCharsetName) {
        try {
            str = new String(str.getBytes(charsetName), toCharsetName);

        } catch (UnsupportedEncodingException ex) {
            System.out.println("字符串编码转换异常:" + ex.getMessage());

        }

        return str;

    }

    private static String getChinese(String chinese) {

        chinese = conversionStr(chinese, "ISO8859-1", "GB2312");

        chinese = chinese.substring(0, 1);
        if (chinese.equals("A") || chinese.equals("B") || chinese.equals("C") || chinese.equals("D") || chinese.equals("E") || chinese.equals("F") || chinese.equals("G") ||
                chinese.equals("H") || chinese.equals("I") || chinese.equals("J") || chinese.equals("K") || chinese.equals("L") || chinese.equals("M") || chinese.equals("N") ||
                chinese.equals("O") || chinese.equals("P") || chinese.equals("Q") || chinese.equals("R") || chinese.equals("S") || chinese.equals("T") || chinese.equals("U") ||
                chinese.equals("V") || chinese.equals("W") || chinese.equals("X") || chinese.equals("Y") || chinese.equals("Z")) {
            chinese = chinese.substring(0, 1);
        }else {
            if (chinese.equals("a")) {
                chinese = "A";
            } else if (chinese.equals("b")) {
                chinese = "B";
            } else if (chinese.equals("c")) {
                chinese = "C";
            } else if (chinese.equals("d")) {
                chinese = "D";
            } else if (chinese.equals("e")) {
                chinese = "E";
            } else if (chinese.equals("f")) {
                chinese = "F";
            } else if (chinese.equals("g")) {
                chinese = "G";
            } else if (chinese.equals("h")) {
                chinese = "H";
            } else if (chinese.equals("i")) {
                chinese = "I";
            } else if (chinese.equals("j")) {
                chinese = "J";
            } else if (chinese.equals("k")) {
                chinese = "K";
            } else if (chinese.equals("l")) {
                chinese = "L";
            } else if (chinese.equals("m")) {
                chinese = "M";
            } else if (chinese.equals("n")) {
                chinese = "N";
            } else if (chinese.equals("o")) {
                chinese = "O";
            } else if (chinese.equals("p")) {
                chinese = "P";
            } else if (chinese.equals("q")) {
                chinese = "Q";
            } else if (chinese.equals("r")) {
                chinese = "R";
            } else if (chinese.equals("s")) {
                chinese = "S";
            } else if (chinese.equals("t")) {
                chinese = "T";
            } else if (chinese.equals("u")) {
                chinese = "U";
            } else if (chinese.equals("v")) {
                chinese = "V";
            } else if (chinese.equals("w")) {
                chinese = "W";
            } else if (chinese.equals("x")) {
                chinese = "X";
            } else if (chinese.equals("y")) {
                chinese = "Y";
            } else if (chinese.equals("z")) {
                chinese = "Z";
            } else {
                chinese = "#";
            }
        }

        return chinese;

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值