- @Test
- public void test04() {
- String strText = "中华人民共和国";
- char c;
- String strRet = "";
- int intAsc;
- String strHex;
- System.out.println(strText);
- for (int i = 0; i < strText.length(); i++) {
- c = strText.charAt(i);
- intAsc = (int) c;
- if (intAsc > 128) {
- strHex = "\\u" + Integer.toHexString(intAsc);
- strRet = strRet + "" + strHex;
- } else {
- strRet = strRet + c;
- }
- }
- System.out.println("unicode:"+strRet);
- }
复制代码 还有一种方式,就是使用JDK带的一个工具(native2ascii )进行转换:
|