Print string literal unicode as the actual character

后端 未结 4 1061
自闭症患者
自闭症患者 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:31

    You're probably going to have to write a parse for these, unless you can find one in a third party library. There is nothing in the JDK to parse these for you, I know because I fairly recently had an idea to use these kind of escapes as a way to smuggle unicode through a Latin-1-only database. (I ended up doing something else btw)

    I will tell you that java.util.Properties escapes and unescapes Unicode characters in this manner when reading and writing files (since the files have to be ASCII). The methods it uses for this are private, so you can't call them, but you could use the JDK source code to inspire your solution.

提交回复
热议问题