package com.yeshi.buwan.util; import javax.persistence.Entity; /** * 将数字转为字母,将字母转为数字 * * @author Administrator * */ @Entity public class StringNumberUtil { private static String[] zms = { "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" }; /** * 将字母转为数字 * * @param st * @return */ public static String convertChar2Int(String st) { String number = ""; for (int i = 0; i < st.length(); i++) for (int j = 0; j < zms.length; j++) { if ((st.charAt(i) + "").trim().equals(zms[j])) { number += ((10 + j) + ""); break; } } return number; } /** * 将数字转为字母 * * @param st * @return */ public static String convertInt2Char(String st) { if (st.length() % 2 != 0) return ""; String ch = ""; for (int i = 0; i < st.length(); i += 2) { String number = ((st.charAt(i) + "").trim() + (st.charAt(i + 1) + "").trim()); ch += zms[Integer.parseInt(number) - 10]; } return ch; } }