Java - 从字符串计算字符串
在我的 Java 代码中,我有这个片段:
String str = "\\u9601";
但我希望它是:
String str = "\u9601";
它代表一个宽字符。
有办法做到这一点吗?
请帮忙。 提前致谢。
补充:
很抱歉这个问题描述得不好。
System.out.print("\u9601"); //this will display a Chinese character
我当前正在请求一个网页(URL),该网页(URL)以 JSON 响应。 如果使用“System.out.print”转储到控制台,JSON 将变成 6 个可见字符 \、u、9、 6、0和1,但在eclipse中不是汉字。
所以实际上我想要的是 API 可以将“\\u9601”转换为“\u9601”,因为我无法对来自网站的内容的 Java 源进行硬编码。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望它是
String str = "\u9601";
,请保持这种方式!根据更新的问题进行编辑
StringEscapeUtils.unescapeJava 方法位于 Apache Commons Lang API 应该会有所帮助:
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: