Java - Evaluate String from String

心已入冬 提交于 2020-01-03 05:13:37

问题


in my Java code I have this snippet:

String str = "\\u9601";

But I want it to be:

String str = "\u9601";

which represents a wide character.

Are there ways to do this?

Please help. Thanks in advance.

Supplementary:

Sorry for the badly-described question.

System.out.print("\u9601"); //this will display a Chinese character

I am currently request a webpage(URL) which response with a JSON. If dumped to Console using "System.out.print", the JSON will turn out to be 6 visible characters \, u, 9, 6, 0 and 1,but not a Chinese character in eclipse.

So actually what I want is are there APIs can convert "\\u9601" to "\u9601", since I can not hard code the Java source for the contents comes from website.


回答1:


If you want it to be String str = "\u9601";, keep it that way!

Edit based on the updated question

The StringEscapeUtils.unescapeJava method in the Apache Commons Lang API should be of help:

    String str = "\\u9601";
    str = StringEscapeUtils.unescapeJava(str);
    System.out.println(str);


来源:https://stackoverflow.com/questions/4290028/java-evaluate-string-from-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!