简体   繁体   English

将unicode文字字符串打印为Unicode字符

[英]Print unicode literal string as Unicode character

I need to print a unicode literal string as an equivalent unicode character. 我需要打印一个unicode文字字符串作为等效的unicode字符。

System.out.println("\u00A5"); // prints  ¥

System.out.println("\\u"+"00A5"); //prints \u0045  I need to print it as ¥ 

How can evaluate this string a unicode character ? 如何评估此字符串是unicode字符?

As an alternative to the other options here, you could use: 作为此处其他选项的替代方法,您可以使用:

int codepoint = 0x00A5; // Generate this however you want, maybe with Integer.parseInt
String s = String.valueOf(Character.toChars(codepoint));

This would have the advantage over other proposed techniques in that it would also work with Unicode codepoints outside of the basic multilingual plane. 这将优于其他提出的技术,因为它还可以与基本多语言平面之外的Unicode码点一起使用。

If you have a string: 如果你有一个字符串:

System.out.println((char)(Integer.parseInt("00A5",16)));

probably works (haven't tested it) 可能有效(尚未测试过)

Convert it to a character. 将其转换为角色。

System.out.println((char) 0x00A5);

This will of course not work for very high code points, those may require 2 "characters". 这当然不适用于非常高的代码点,那些可能需要2个“字符”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM