Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字列をスペイン語の文字 (óáñ) と比較する必要があるプログラムがあります。
残念ながら、このコードはコンパイルさえしません:
if str == "Caló" puts "OK!"
置いてみました
# encoding: utf-8
ファイルの先頭にありますが、同じ「無効なマルチバイト文字 (UTF-8)」が表示されます。
何か案が?
やってみる
if str.encode('utf-8') == "Caló" puts "OK!" end
または動作しない場合
if str.force_encoding('utf-8') == "Caló" puts "OK!" end