简体   繁体   English

用Unicode转换字符串以在Java中显示unicode?

[英]Convert string with Unicode to show unicode in java?

I am trying to convert strings that contain a unicode to the actual character but everything I have found so far either only work if the string is only the unicode or converts the symbol to the code. 我正在尝试将包含unicode的字符串转换为实际字符,但到目前为止,我发现的所有内容仅在字符串仅为unicode的情况下才有效,或者将符号转换为代码。

This is the string I am using as an example right now 这是我现在用作示例的字符串

Rebroadcast of Shows from the past Week! RPGs, Talk shows, Science, Wisdom, Vampires and more - Good stuff! \\u003c3 - !rbschedule for more info

I am getting this in from an API call so I can't just write it as \\ instead of the \\\\. 我是通过API调用获取此信息的,所以我不能只是将其写为\\而不是\\\\。

如果将所有“ //”动态替换为“ /”怎么办?

\\

That is called escaping , and it is what is currently blocking you from seeing the < character. 这称为转义 ,这是当前阻止您看到<字符的原因。
Un-escaping is not what you'd actually want to do manually , as there are many caveats. 退出转义并不是您真正想要手动执行的操作 ,因为有很多警告。

You might want to use Apache common-text StringEscapeUtils#unescapeJava 您可能要使用Apache common-text StringEscapeUtils#unescapeJava

final String result = StringEscapeUtils.unescapeJava(yourString);

That will output "...Good stuff! <3 - !rbschedule for more info..." 这将输出“ ...好东西!<3-!rbschedule了解更多信息...”


The Maven dependency Maven依赖

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-text</artifactId>
    <version>1.6</version>
</dependency>

Or for Gradle 或摇篮

compile group: 'org.apache.commons', name: 'commons-text', version: '1.6'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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