Skip to content

Instantly share code, notes, and snippets.

@kmdsbng
Created September 1, 2011 04:22
Show Gist options
  • Select an option

  • Save kmdsbng/1185445 to your computer and use it in GitHub Desktop.

Select an option

Save kmdsbng/1185445 to your computer and use it in GitHub Desktop.
invalidな文字を含むUTF-8 で、invalidな文字を ? に置換する
# http://d.hatena.ne.jp/yarb/20110112/p1
line = line.encode("UTF-16BE", :invalid => :replace, :undef => :replace, :replace => '?').encode("UTF-8")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment