【发布时间】:2015-04-07 14:04:06
【问题描述】:
我正在 Clojure 中实现一个纸牌游戏,我想使用 unicode 字符来表示花色:
(def color-str "Maps card colors to strings"
{ :kreuz "♣", :grun "♠", :herz "♥", :schell "♦" })
但是,我得到的不是所需的字符:
{:grun "ΓÖá", :herz "ΓÖÑ", :kreuz "ΓÖú", :schell "ΓÖª"}
同样,当我将color-str 重新定义为:
(def color-str "Maps card colors to strings"
{ :kreuz \u2663, :grun \u2660, :herz \u2665, :schell \u2666 })
我明白了:
{:grun \ΓÖá, :herz \ΓÖÑ, :kreuz \ΓÖú, :schell \ΓÖª}
文件保存为没有 BOM 的 UTF-8。我已经尝试添加:
:javac-options ["-encoding utf8"]
:jvm-opts ["-Dfile.encoding=UTF-8"]
到project.clj 文件,但它没有帮助。我知道控制台(Cygwin 的 Bash)能够显示这些字符 - 当我将 { :kreuz "♣", :grun "♠", :herz "♥", :schell "♦" } 直接复制粘贴到 REPL 中时,它会正确显示它们。
我错过了什么?
【问题讨论】:
-
控制台的字符编码设置为不同于 Clojure 认为的设置。
-
谢谢!运行
cmd /c chcp 65001确实解决了问题。 -
@maddening 你应该把它作为答案发布并接受它。
-
我希望@Jesper 发布它,但我也可以做到。