How to write unicode cross symbol in Java?

2019-02-01 07:17发布

I'm trying to write this unicode cross symbol (

4条回答
别忘想泡老子
2楼-- · 2019-02-01 07:35

You're looking for U+10035, which is outside the Basic Multilingual Plane. That means you can't use \u to specify the value, as that only deals with U+0000 to U+FFFF - there are always exactly four hex digits after \u. So currently you've got U+1003 ("MYANMAR LETTER GHA") followed by '5'.

Unfortunately Java doesn't provide a string literal form which makes characters outside the BMP simple to express. The only way of including it in a literal (but still in ASCII) is to use the UTF-16 surrogate pair form:

String cross = "\ud800\udc35";

Alternatively, you could use the 32-bit code point form as an int:

String cross = new String(new int[] { 0x10035 }, 0, 1);

(These two strings are equal.)

Having said all that, your console would still need to support that character - you'll need to try it to find out whether or not it does.

查看更多
叛逆
3楼-- · 2019-02-01 07:38

0x10035 is a supplemental Unicode character. You'll need to font that supports it if you want your program to render it.

http://www.oracle.com/technetwork/articles/javase/supplementary-142654.html

查看更多
Deceive 欺骗
4楼-- · 2019-02-01 07:42

I believe Java represents Unicode characters from 0x0000 to 0xFFFF. Java would evaluate "\u10035" to whatever "\u1003" is and a 5 after that.

查看更多
虎瘦雄心在
5楼-- · 2019-02-01 07:53

Unicode escapes are 4 characters long. You are printing \u1003 followed by '5'. Are you sure you have the right code point?

查看更多
登录 后发表回答