/*
 * *************************************************
 * Copyright (c) 2018 QMTH. All Rights Reserved.
 * Created by Deason on 2018-07-12 15:31:10.
 * *************************************************
 */

package cn.com.qmth.examcloud.core.questions.base.converter.utils;

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

    /**
     * 将(1-26)区间的数字转换成字母
     */
    public static String toEnNumber(int number) {
        String result = "";
        if (number < 1 || number > 26) {
            //限制支持的数字范围
            return result;
        }
        return CHAR[number - 1];
    }

    /**
     * 将字符串内的字母转换成(1-26)区间的数字
     */
    public static String toNumber(String character) {
        if (character == null) {
            return "";
        }
        StringBuilder str = new StringBuilder();
        char[] chars = character.toUpperCase().toCharArray();
        for (char c : chars) {
            if (String.valueOf(c).matches("[a-zA-Z]")) {
                str.append(c - 64);
            } else {
                str.append(c);
            }
        }
        return str.toString();
    }

}