Encoding problem when i use unpack


#1

Hi,

I’ve a very strange problem when i use both unpack and encode, lets me
show you :
irb(main):034:0> “=E9”.unpack(“M*”)[0]
=> “\xE9”
irb(main):035:0> “=E9”.unpack(“M*”)[0].encode “UTF-8”, “ISO-8859-1”
=> “\xE9”
irb(main):036:0> “\xE9”.encode “UTF-8”, “ISO-8859-1”
=> “é”
irb(main):037:0> “\xE9”.encoding.name
=> “ASCII-8BIT”
irb(main):038:0> “=E9”.unpack(“M*”)[0].encoding.name
=> “US-ASCII”
irb(main):039:0>
“=E9”.unpack(“M*”)[0].force_encoding(“ASCII-8BIT”).encoding.name
=> “ASCII-8BIT”
irb(main):040:0>
“=E9”.unpack(“M*”)[0].force_encoding(“ASCII-8BIT”).encode “UTF-8”,
“ISO-8859-1”
=> “\xE9”

Could you explain me how can i unpack then encode to UTF-8 ?