开发者

How can I get utf8 characters from File#path

File#path is giving me Latin-1 characters -- is there a way to get it to give me utf8 characters, or should I just convert what it returns? If so, what's the best/easiest way to conver开发者_开发问答t?

elaboration

So, I know I can do this:

Iconv.new('UTF-8','LATIN1').iconv(File.basename(file.path))

But I'm wondering if there is a more elegant way to tell File to give me utf8 to begin with.

This is especially important because for some reason I get back a different charset on different systems. On my OS X dev machine, it looks like I get back utf8. On my linux server, latin-1.


Use a magic comment in a first line of your document:

#encoding: UTF-8


See $LANG and $LC_CTYPE (environment variables).

These variables also determine the default value for the encoding defaults in 1.9, and so changes you make today will also work if you later port your code to 1.9.

N.B. Windows is a slightly different beast in this regard, so you may need further information to tackle that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜