输出汉字的uincode编码

bill_hai 2007-10-19 09:27:12
我想输出一个汉字的unicode编码,
该怎么办呀??
最好用printf()方法.
...全文
131 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
public class CharTest {
public static void main(String[] args) {
char c = '国';
// System.out.printf 仅在 JDK 1.5 及以上的版本有效
System.out.printf("“%c”的Unicode编码:%04X%n", c, (int)c);
}
}
LIHBJOB 2007-11-05
  • 打赏
  • 举报
回复
Ailen5 的方法最方便了
哈哈!
牛!
iori890218 2007-11-05
  • 打赏
  • 举报
回复
public String toUnicode(String str) {
char[]arChar=str.toCharArray();
int iValue=0;
String uStr="";
for(int i=0;i<arChar.length;i++) {
iValue=(int)str.charAt(i);
if(iValue<=256){
uStr+="/u00"+Integer.toHexString(iValue).toUpperCase();
}else{
uStr+="/u"+Integer.toHexString(iValue).toUpperCase();
}
}
return uStr;
}
纯JAVA写的一个转unicode的方法
「已注销」 2007-10-19
  • 打赏
  • 举报
回复

System.out.println((int)'我');
johnsoncr 2007-10-19
  • 打赏
  • 举报
回复
String s = "\u0057\u0065\u006C\u0063\u006F\u006D\u0065";
该语句打印出来的结果是字符串“Welcome”
转义序列的形式为\uyyyy,其中yyyy表示四位十六进制码值。
通过不同的码值我们可以表示不同国家的各种符号,Unicode联盟的网站有一个到码表的链接,列出了16位码值。英语,法语,德语,葡萄牙语和西班牙语字符都在Basic Latin区,日语字符在Hiragana区,俄语字符在Cyrillic区,汉语字符在CJK Unified Ideographs 区。
Ailen5 2007-10-19
  • 打赏
  • 举报
回复
在dos 环境下输入native2ascii打回车,输入所要转换的中文文字,再打回车,中文转换为unicode编码

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧