Ruby 1.8和UTF-8字符串大小写语句比较 [英] Ruby 1.8 and UTF-8 string case statement compare

查看:127
本文介绍了Ruby 1.8和UTF-8字符串大小写语句比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rake任务(在lib/tasks目录中),该任务在共享的Web主机上与cron一起运行.问题是我想使用大小写语句比较UTF-8字符串,但是我的源代码不是UTF-8编码的.如果我将源代码另存为UTF-8,则尝试启动它时会出错:(

I have a Rake task (in lib/tasks directory) that I run with cron on my shared web hosting. The problem is that I want to compare a UTF-8 string using case statment but my source code is not UTF-8 encoded. If I save source code as UTF-8 there is error when I try to start it :(

我该怎么办?

可以从外部UTF-8 txt文件读取此字符串吗?

May be read this strings from external UTF-8 txt file?

P.S.我正在使用Ruby 1.8

P.S. I'm using Ruby 1.8

P.S.我的意思是这样比较:

P.S. I mean compare this way:

result = case utf8string
   when 'АБВ': 1
   when 'ГДИ': 2
   when 'ЙКЛ': 3
   when 'МНО': 4
   else 5
end

推荐答案

我想说您需要更改文本编辑器,因为UTF-8不需要BOM. UTF-8与字节顺序无关.有关详细信息,请参见链接文本.

I'd say you need to change your text editor as BOM is not needed for UTF-8. UTF-8 is not byte-order dependent. See link text for details.

这篇关于Ruby 1.8和UTF-8字符串大小写语句比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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