简体   繁体   中英

Print unicode characters encoded

Let's say we have string like P\ř\íprava
How can we print it out with Java (println, printf, ...) so the unicode characters won't be decoded?

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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