获取角色的unicode值 [英] Get unicode value of a character

查看:115
本文介绍了获取角色的unicode值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java中是否有任何方法可以让我获得与任何字符等效的Unicode?例如。

Is there any way in Java so that I can get Unicode equivalent of any character? e.g.

假设方法 getUnicode(char c)。来电 getUnicode('÷')应该返回 \ u00f7

Suppose a method getUnicode(char c). A call getUnicode('÷') should return \u00f7.

推荐答案

你可以在这里使用单行代码对任何Java字符进行处理:

You can do it for any Java char using the one liner here:

System.out.println( "\\u" + Integer.toHexString('÷' | 0x10000).substring(1) );

但它只能用于Unicode字符直到Unicode 3.0,这就是为什么我让你精确的可以为任何Java char做这件事。

But it's only going to work for the Unicode characters up to Unicode 3.0, which is why I precised you could do it for any Java char.

因为Java是在Unicode 3.1出现之前设计的,因此Java的char原语不足以代表Unicode 3.1及以上:没有一个Unicode字符到一个Java char映射了(而不是使用了一个怪异的hack)。

Because Java was designed way before Unicode 3.1 came and hence Java's char primitive is inadequate to represent Unicode 3.1 and up: there's not a "one Unicode character to one Java char" mapping anymore (instead a monstrous hack is used).

所以你真的必须在这里检查你的要求:你需要支持Java吗? char或任何可能的Unicode字符?

So you really have to check your requirements here: do you need to support Java char or any possible Unicode character?

这篇关于获取角色的unicode值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆