【问题标题】:UTF-8 characters not displayed correctly in consoleUTF-8 字符在控制台中未正确显示
【发布时间】: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 发布它,但我也可以做到。

标签: utf-8 clojure console


【解决方案1】:

我的解决方案是运行:

cmd /c chcp 65001

它将控制台中的默认代码页设置为 UTF-8。默认情况下,CMD 使用默认为当前语言和本地化设置的代码页,例如437 for United States。将其设置为 UTF-8 (65001) 即可解决此问题。

在@Jesper 建议它与控制台编码有关之后,我从this question 的第二个答案中得到了这个想法。

【讨论】:

    【解决方案2】:

    控制台的字符编码设置为不同于 Clojure 认为的设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      • 2011-08-09
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2011-06-15
      相关资源
      最近更新 更多