Skip to content

Instantly share code, notes, and snippets.

@ihower
Created May 21, 2009 17:18
Show Gist options
  • Save ihower/115577 to your computer and use it in GitHub Desktop.
Save ihower/115577 to your computer and use it in GitHub Desktop.
convert big5 hex codepoint to utf-8 string
require 'iconv'
$KCODE = 'u'
hex_string ="4A6BA441" # A441 is big5 "乙"
big5_string = hex_string.scan(/../).map{ |c| c.hex }.pack("c*")
iconv = Iconv.new("utf-8//ignore", "big5")
utf8_string = iconv.iconv(big5_string) # convert to utf-8
puts utf8_string # output JK乙
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment