Forum: Ruby Encoding problem when i use unpack

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
oxman b. (Guest)
on 2009-03-27 19:45
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 ?
This topic is locked and can not be replied to.