简体   繁体   English

打印已编码的unicode字符

[英]Print unicode characters encoded

Let's say we have string like P\ř\íprava 假设我们有类似P\ř\íprava字符串
How can we print it out with Java (println, printf, ...) so the unicode characters won't be decoded? 我们如何使用Java(println,printf,...)将其打印出来,以使unicode字符不会被解码?

Final 最后

I ended up using something like this 我最终使用了这样的东西

String data = "P\u0159\u00edprava";
data = data.replace("\\","\\\\");
// "\\" is a single backslash "\\\\" then double backslashes
System.out.println(data);

在您自己的'\\'字符前添加'\\'应该可以解决问题:

System.out.println("P\\u0159\\u00edprava");

转义反斜杠:

System.out.println("P\\u0159\\u00edprava");

Use StringEscapeUtils of commons-lang3 . 使用StringEscapeUtils公地lang3

The code is here (see the method public boolean translate(int codepoint, Writer out) throws IOException ): http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java?revision=1148520&view=markup 代码在此处(请参见方法public boolean translate(int codepoint, Writer out) throws IOException ): http : //svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/ apache / commons / lang3 / text / translate / UnicodeEscaper.java?revision = 1148520&view = markup

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

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