Encoding problem when i use unpack

O

Oxman Oxman

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 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top