简体   繁体   English

Ruby显示Unicode字符

[英]Ruby display unicode character

I'm trying to print out some Unicode characters: 我正在尝试打印一些Unicode字符:

# encoding: utf-8
puts "ử ậ ắ ặ ố ồ"

If I run it through Powershell, this is what I get: 如果我通过Powershell运行它,那么我将得到:

在此处输入图片说明

If I run it through cmd, this is what I get: 如果通过cmd运行它,我将得到:

在此处输入图片说明

If I run it in Eclipse (with Aptana Studio 3 plugin), this is what I get: 如果我在Eclipse中运行它(使用Aptana Studio 3插件),那么我会得到:

在此处输入图片说明

Is it a problem with my system/software or is it Ruby's problem? 我的系统/软件有问题还是Ruby的问题? How can I get it to work? 我如何使它工作?

It works on Ideone though: http://ideone.com/PdycKH 它可以在Ideone上使用: http ://ideone.com/PdycKH

Ruby supports it no problem, and setting the formatting at the top of the file is the way to go. Ruby完全没有问题,将格式设置在文件顶部是可行的方法。

The issue is the display via the command line window. 问题是通过命令行窗口显示。 You need to use both a font and character page that supports Unicode display. 您需要同时使用支持Unicode显示的字体和字符页面。

See this question regarding doing this in the Windows command line. 请在Windows命令行中查看有关此操作的问题

About the chcp command 关于chcp命令

I figured it out: 我想到了:

  • For cmd and Powershell , I have to change the font (I changed to Consolas) 对于cmdPowershell ,我必须更改字体(我更改为Consolas)
  • In Eclipse, I have to change the encoding: go to Run/Run configurations, select the Common tab, change the Encoding to Other: UTF-8 在Eclipse中,我必须更改编码:转到“运行/运行”配置,选择“通用”选项卡,将“ Encoding更改为“ Other: UTF-8

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

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