javastringunicode

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.

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 \\.


Solution

  • \\
    

    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

    final String result = StringEscapeUtils.unescapeJava(yourString);
    

    That will output "...Good stuff! <3 - !rbschedule for more info..."


    The Maven dependency

    <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'