在java中用什么方法取得字符的ASCII值和Unicode值

haif1978 2002-06-06 11:22:25
在java中用什么方法取得字符的ASCII值和Unicode值
...全文
99 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyyoung 2002-06-07
  • 打赏
  • 举报
回复
public static String dumpHEX(String rStr)
{
return dumpHEX(rStr, null);
}
public static String dumpHEX(String rStr, String rEncoding)
{
byte[] buf = null;
try
{
if(rEncoding != null)
buf = rStr.getBytes(rEncoding);
else
buf = rStr.getBytes();
//System.out.println(new String(rStr.getBytes(rEncoding)));
}
catch(Exception e)
{
e.printStackTrace();
}
StringBuffer sb = new StringBuffer();
for(int i = 0; i < buf.length; i ++ )
{
sb.append(dumpHEXStr(buf[i]) + " ");
}
System.out.println(sb.toString());
return sb.toString();
}
public static String dumpHEXStr(byte b)
{
return ("" + "0123456789ABCDEF".charAt(0xf & b >> 4) + "0123456789ABCDEF".charAt(b & 0xf));
}

use dumpHEX(str,"UnicodeBig");
---------------
shmliu@sina.com
littlecong 2002-06-07
  • 打赏
  • 举报
回复
char c = '虫';
System.out.println((int)c);
haif1978 2002-06-06
  • 打赏
  • 举报
回复
大家帮个忙好么!
我等着急用!

62,614

社区成员

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

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