java 数字与字母的转换

时间:2025-04-19 20:30:02
public class TestConvert {

	// 将字母转换成数字_1
	public static String t1(String input) {
		String reg = "[a-zA-Z]";
		StringBuffer strBuf = new StringBuffer();
		input = ();
		if (null != input && !"".equals(input)) {
			for (char c : ()) {
				if ((c).matches(reg)) {
					(c - 96);
				} else {
					(c);
				}
			}
			return ();
		} else {
			return input;
		}
	}

	// 将字母转换成数字
	public static void letterToNum(String input) {
		for (byte b : ()) {
			(b - 96);
		}
	}

	// 将数字转换成字母
	public static void numToLetter(String input) {
		for (byte b : ()) {
			((char) (b + 48));
		}
	}

	public static void main(String[] args) {
		String i1 = "abcdef";
		String i2 = "123456";
		letterToNum(i1);
		();
		numToLetter(i2);
	}
}