将传入字符串上的 unicode 表示形式转换为 UTF-8? [英] Convert unicode representations on incoming string to UTF-8?
问题描述
我正在读取一些已经转换为 html 样式 υ 代码的数据.
I'm reading some data that has already been converted to html style υ code.
我现在需要将其转换回 UTF-8 字符以供查看.不幸的是,我无法使用浏览器查看字符串.
I now need to convert this back to UTF-8 characters for viewing. Unfortunately I can't use a browser to view the string.
我已经阅读了有关 Java 转换的内容,似乎如果您有一个 \uxxxx 字符串,那么编译器会为您进行转换;但是这当然行不通,因为我想读取动态字符串.
I've read around about conversion in java and it seems if you have a string of \uxxxx then the compiler will convert for you; However that wont work of course because I want to read in dynamic strings.
这能做到吗?
非常感谢!丹
推荐答案
您需要使用:
String StringEscapeUtils.unescapeJava(String str)
来自 Apache 公共图书馆.
from the Apache Commons Library.
它将在输入字符串中找到\uxxxx
序列并将它们转换为普通的Java 字符串.
It will find \uxxxx
sequences in the input string and convert them to a normal Java String.
这篇关于将传入字符串上的 unicode 表示形式转换为 UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!