就像图片一样,我想在编码的UTF-8字符串和Java中的 native 字符串之间进行转换。 有人会提出一些建议吗?非常感谢!
ps。 例如,
String a = "这是一个例子,this is a example";
String b = null;
// block A: processing a, and let b = "这是一个例子,this is a example"
如何实现“A block ”?
最佳答案
Apache Commons Lang StringEscapeUtils.unescapeXml(...)
就是你想要的。根据原始字符串的来源,其中一种 HTML 变体可能更合适。
像这样使用:
String a = "这是一个例子,this is a example";
String b = StringEscapeUtils.unescapeXml(a);
// block A: processing a, and let b = "这是一个例子,this is a example"
System.out.println(a);
System.out.println(b);
输出:
这是一个例子,this is a example
这是一个例子,this is a example
也有其他转换方法。
关于java - 如何在Java中UTF-8和 native 字符串之间进行转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38827553/