Skip to content

Instantly share code, notes, and snippets.

@ukstudio
Created February 23, 2009 03:35
Show Gist options
  • Save ukstudio/68774 to your computer and use it in GitHub Desktop.
Save ukstudio/68774 to your computer and use it in GitHub Desktop.
# coding: UTF-8
str_utf = "hoge"
str_euc = "hoge".encode("EUC-JP")
# ASCII互換コーディングをもつ7bitクリーンな文字列は
# エンコーディングに関わらずASCIIとして扱える
p str_utf == str_euc #=> true
p /hoge/ =~ str_utf #=> 0
p /hoge/ =~ str_euc #=> 0
str_utf_multi_byte = "あいうえお"
str_euc_multi_byte = "あいうえお".encode("EUC-JP")
p str_utf_multi_byte == str_euc_multi_byte #=> false
p /あいうえお/ =~ str_utf_multi_byte #=> 0
p /あいうえお/ =~ str_euc_multi_byte #=> Encoding::CompatibilityError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment