Eclipse:在文本编辑器中使用 UTF-8 编码会使字符串无法正常工作,我该如何解决?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14167880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse:Using UTF-8 encoding in the text editor make the Strings not work properly, how can I fix that?
提问by ksm001
I have some Greek comments in the code and when I enter a Greek letter it says "Save us UTF-8"
我在代码中有一些希腊语注释,当我输入一个希腊字母时,它说“Save us UTF-8”
Then if I do so and re run the program the previously displayed Strings would not work properly.
然后,如果我这样做并重新运行程序,先前显示的字符串将无法正常工作。
For example I'm working on an encryption algorithm(Simplified Des) and this is what I get with the Cp1252 encoding in the text editor as output:
例如,我正在研究一种加密算法(Simplified Des),这就是我在文本编辑器中使用 Cp1252 编码作为输出得到的结果:
?O [áa[aá?j×jt
INFO BOB 57674
the first line is the encrypted version and the second is the decrypted version this is what I get when I change the encoding to UTF-8
第一行是加密版本,第二行是解密版本,这是我将编码更改为 UTF-8 时得到的
?O [?a[a?j?jt
???NFO???BOB???7???74
I don't understand what's going on here, I've never seen anything like this before. Can someone help me? Thank you in advance
我不明白这里发生了什么,我以前从未见过这样的事情。有人能帮我吗?先感谢您
回答by Marcel St?r
There's (at least) one discussion here on SO about Should source code be saved in UTF-8 formator not.
这里(至少)有一个关于是否应将源代码保存为 UTF-8 格式的讨论。
Personally, I'd advise against it. I'd much rather use the \uXXXXnotationto encode those Greek characters in the source code and keep the other settings untouched.
就个人而言,我建议不要这样做。我更愿意使用该\uXXXX符号对源代码中的希腊字符进行编码,并保持其他设置不变。

