获取显示字符,如[äöüßÄÖÜß](utf-8编码)? (可能Windows特定问题?) [英] Get pry to display characters like [äöüßÄÖÜß] (utf-8 encoding)? (Possibly Windows-specific issue?)

查看:431
本文介绍了获取显示字符,如[äöüßÄÖÜß](utf-8编码)? (可能Windows特定问题?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[我使用这些德语字符的所有脚本都是UTF-8本身,在顶部有 #encoding:utf-8 Encoding.external_default ='utf-8',这不是真的相关我认为,因为在脚本中定义的字符串中的德语字符)



所有这些都在Windows命令提示符下显示正常,并使用irb等。



我甚至不能在pry提示符下输入这些字符。正在尝试在中粘贴<; code>将冻结

使用pry,我运行一个脚本 GC =äöüÄÖÜß在它,这是一种garbledeegook我得到:

  [1] pry(main)> GC 
=>├ñ├Â├╝├ä├û├£├ƒ
[2] pry(main)> GC.split(' c}
ä
├Â
├╝
Ä
Ö
Ü
ß
=> ; [├ñ,├Â,├╝,├ä,├û,├£,├ƒ]
[3] File.open(output.txt,'w'){| f | GC.split('')。each {| c | f.puts c}}
pre>

由最后一行创建的测试文件 output.txt ,但 > in utf-8,并读为:

 ä
ö
ü
Ä
Ö
Ü
ß

有没有任何想法如何解决这个?

解决方案

我知道如果你安装 Ruby c $ c> readline 支持,那么你没有这个问题。要这样做,如果你使用 rbenv (与ruby-build),你将需要这样的东西:

  RUBY_CONFIGURE_OPTS = -  with-readline-dir =`brew --prefix readline`rbenv install 1.9.3 

我不知道是否还有其他解决方案。


[All the scripts I'm working with with these German characters are in UTF-8 themselves, have #encoding: utf-8 at the top (and Encoding.external_default = 'utf-8', not that that's really relevant I think because German chars in strings that are defined within the script don't get displayed right.)]

All these things display fine at the windows command prompt and using irb etc.

I can't even enter these characters at the pry prompt, though. Attempting to paste in puts "äöüÄÖÜß" gets puts ". Attempting to actually type them freezes pry somehow, and I have to ^D out.

Using pry, I ran a script with GC = "äöüÄÖÜß" in it, and this is the kind of garbledeegook I get:

[1] pry(main)> GC                               
=> "├ñ├Â├╝├ä├û├£├ƒ"                             
[2] pry(main)> GC.split('').each{ |c| puts c }  
ä                                              
├                                              
├╝                                              
Ä                                              
Ö                                              
Ü                                              
ß                                              
=> ["├ñ", "├Â", "├╝", "├ä", "├û", "├£", "├ƒ"]
[3] pry(main)> File.open("output.txt", 'w'){|f| GC.split('').each{ |c| f.puts c } }

The test file output.txt created by that last line, however, is in utf-8 and reads:

ä
ö
ü
Ä
Ö
Ü
ß

Does anyone have any ideas how to fix this?

解决方案

I know that if you install Ruby with readline support, then you doesn't have this problem. To do so you will need something like this if you are using rbenv (with ruby-build):

RUBY_CONFIGURE_OPTS="--with-readline-dir=`brew --prefix readline`" rbenv install 1.9.3

I don't know if there are other solutions though.

这篇关于获取显示字符,如[äöüßÄÖÜß](utf-8编码)? (可能Windows特定问题?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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