Print string literal unicode as the actual character

后端 未结 4 1055
自闭症患者
自闭症患者 2020-12-30 03:44

In my Java application I have been passed in a string that looks like this:

\"\\u00a5123\"

When printing that string into the console, I get the same string

4条回答
  •  情书的邮戳
    2020-12-30 04:15

    I wrote a little program:

    public static void main(String[] args) {
        System.out.println("\u00a5123");
    }
    

    It's output:

    ¥123

    i.e. it output exactly what you stated in your post. I am not sure there is not something else going on. What version of Java are you using?

    edit:

    In response to your clarification, there are a couple of different techniques. The most straightforward is to look for a "\u" followed by 4 hex-code characters, extract that piece and replace with a unicode version with the hexcode (using the Character class). This of course assumes the string will not have a \u in front of it.

    I am not aware of any particular system to parse the String as though it was an encoded Java String.

提交回复
热议问题