如何在 Java/Eclipse 中使用特殊字符 [英] How to use Special Chars in Java/Eclipse

查看:53
本文介绍了如何在 Java/Eclipse 中使用特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Java/Eclipse 中使用/显示 ♥、♦、♣ 或 ♠ 等字符?

How can I use/display characters like ♥, ♦, ♣, or ♠ in Java/Eclipse?

当我尝试直接使用它们时,例如在源代码中,Eclipse 无法保存文件.

When I try to use them directly, e.g. in the source code, Eclipse cannot save the file.

我能做什么?

如何找到 unicode 转义序列?

How can I find the unicode escape sequence?

推荐答案

问题是您使用的字符无法在您将文件设置为 (Cp1252) 的编码中表示.在我看来,您基本上有两个选择:

The problem is that the characters you are using cannot be represented in the encoding you have the file set to (Cp1252). The way I see it, you essentially have two options:

选项 1.更改编码. 根据IBM,您应该将编码设置为UTF-8.我相信这会解决您的问题.

Option 1. Change the encoding. According to IBM, you should set the encoding to UTF-8. I believe this would solve your problem.

  • 将全局文本文件编码首选项 Workbench > Editors 设置为UTF-8".
  • 如果需要 UTF-8 以外的编码,请在单个文件上设置编码,而不是使用全局首选项设置.为此,请使用文件 > 属性 > 信息菜单选项来设置单个文件的编码.

选项 2.删除Cp1252"字符编码不支持的字符.您可以将不支持的字符替换为 Unicode 转义序列 (uxxxx).虽然这可以让您保存文件,但它不一定是最佳解决方案.

Option 2. Remove the characters which are not supported by the "Cp1252" character encoding. You can replace the unsupported characters with Unicode escape sequences (uxxxx). While this would allow you to save your file, it is not necessarily the best solution.

对于您在问题中指定的字符,这里是 Unicode 转义序列:

For the characters you specified in your question here are the Unicode escape sequences:

♥ u2665
♦ u2666
♣ u2663
♠ u2660

这篇关于如何在 Java/Eclipse 中使用特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆