Encoding problem when i use unpack


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
irb(main):038:0> “=E9”.unpack(“M*”)[0].encoding.name
“=E9”.unpack(“M*”)[0].force_encoding(“ASCII-8BIT”).encode “UTF-8”,
=> “\xE9”

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs