开发者

File.open with ruby on windows with a unicode filename

I have a script running on Ruby 1.9.1 on Windows 7

I've distilled my script down to

File.open("翻譯測試.txt")

and still can't get it to work. I know there are issues with Ruby 1.9 filename handling on windows (Using the Win开发者_C百科dows ANSI library), but would be happy enough with a work around that is callable from Ruby


Most of the Unicode changes like file and directory operations have been improved in 1.9.2 (trunk) and other bigger changes will be merged pretty soon.

As bobince pointed out, this was already asked:

Unicode filenames on Windows in Ruby


This should help you string = "翻譯測試" # by default, string is encoded as "ASCII" string.force_encoding("SHIFT-JIS") # retags the String as SHIFT-JIS or whatever UTF char set that #is in

Heres a nice read a bit about char encoings in 1.9.1

http://yehudakatz.com/2010/05/17/encodings-unabridged/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜