简体   繁体   English

Java将特殊字符转换为Unicode

[英]Java Convert special characters into Unicode

I am using a Special Character in Java, which is causing an issue when I compile with UTF-8 encoding. 我在Java中使用特殊字符,因此在使用UTF-8编码进行编译时会引起问题。 How can I deal with this problem? 我该如何解决这个问题? Here is a code snapshot. 这是一个代码快照。

language = new SelectOption<String>("default", "Default/d�faut");

Here's one more thing: I also have to figure out how to convert it into Unicode. 这是另一件事:我还必须弄清楚如何将其转换为Unicode。

If you know the unicode number of the character you can escape it as follows: 如果您知道字符的unicode号,可以按以下步骤对其进行转义:

language = new SelectOption<String>("default", "Default/d\u2202faut");

where 2202 is the unicode number 其中2202是unicode号

Thanks to @Ernesto Campohermoso and @pratZ it works and here i found a link to convert Special Character to unicode . 感谢@Ernesto Campohermoso@pratZ,它可以工作了, 在这里我找到了将特殊字符转换为unicode的链接。

Like Unicode of this is \� which we can use in Java Class. 就像这个Unicode是\\ uFFFD ,我们可以在Java类中使用它。

If the source file in UTF-8 compile it as javac -encoding UTF-8 ... and there will be no problem. 如果UTF-8中的源文件将其编译为javac -encoding UTF-8 ... ,就不会有问题。

To convert the source file to Unicode-encoded use native2ascii util from JDK http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/native2ascii.html 要将源文件转换为Unicode编码,请使用来自JDK http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/native2ascii.html的 native2ascii util

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

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