作者LPH66 (-858993460)
看板java
标题Re: [问题] unicode转字元
时间Sun Oct 10 23:42:20 2010
※ 引述《Atwo (A兔)》之铭言:
: 想做从使用者输入字元 变成十六进位後 再重新输出一样的字
: char a 由使用者输入
: System.out.println( "\u" + Integer.toHexString(a));
: 上面这句编译时却发生illegal unicode escape错误
: 请问一下这是写法错误吗? 还是有其他问题
先不管什麽格式错误
从十六进位字串变成对应的 unicode 值是相对费工的一件事...
因为最直接的方法就是把那个数值直接丢去一个 char 变数
如果是十六进位字串你还得再转回数字才行
\u1234 这种写法是给 javac 看的
毕竟并不是每个人的环境都可以输入所有 unicode
你在程式里就用程式的做法就好了
--
'Oh, Harry, don't you
see?' Hermione breathed. 'If she could have done
one thing to make
absolutely sure that every single person in this school
will read your interview, it was
banning it!'
---'Harry Potter and the order of the phoenix', P513
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.28.92