Re: [問題] unicode轉字元
※ 引述《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
討論串 (同標題文章)