网友的问题: http://topic.csdn.net/u/20081225/10/949ae344-34d5-4b5d-93ca-f57e0dda5057.html
比如我有一个string str = "0xA0";
这样一个串,有没有什么办法可以转成char s = 0xA0;
注:不是str里单个字符转换,想要的不是srt.charAt(index)这样单个转换;
不知道我表达清楚没有?
果子的答案已经很好了,我这里是我的个人习惯做法,呵呵。
- /**
- * 16进制字符串转字符或数字。
- *
- * @author 老紫竹 JAVA世纪网(java2000.net)
- *
- */
- public class Test {
- public static void main(String[] args) {
- String s = "0x40";
- int b = Integer.parseInt(s.replaceAll("^0[x|X]", ""), 16);
- System.out.println((char)b);
- }
- }