1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| 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;
| }
| }
|
|