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 :(
What I have to do?
May be read this strings from external UTF-8 txt file?
P.S. I'm using Ruby 1.8
P.S. I mean compare this way:
result = case utf8string
when 'АБВ': 1
when 'ГДИ': 2
when 'ЙКЛ': 3
when 'МНО': 4
else 5
end
I found that my problem was not in case statment
The problem was that when I save my source code in UTF-8 format, my text editor add 3 bytes (BOM) at the beginning to indicate that encoding is UTF-8.
UTF-8, UTF-16, UTF-32 & BOM
The error that I get was:
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.
Try using the
mb_chars
method from Rails' ActiveSupport framework: