From: Greg Hurrell Date: 2007-02-25T23:20:05+09:00 Subject: Re: Using unpack on a UTF-8 string On 24 feb, 23:47, Carlos wrote: > > The UNICODE codepoint for the euro sign is 8364. In your string you have > that number encoded as a sequence of bytes [226, 130, 172]. That encoding is > known as UTF-8. #unpack decodifies that sequence of bytes and gives you the > number. > > For analogy, think as if you had the string "\272!\000\000" and did an > #unpack("I"). The sequence of bytes [186, 33, 0, 0] also represent the > number 8364, but this time encoded in the internal format my computer uses. > #unpack retrieves that number. The fact that UTF-8 is used for encoding > UNICODE codepoints is incidental to this. > > To unpack the bytes from a string use #unpack("C*"). Thanks a million, Carlos. I never would have figured that out for myself. I misunderstood the documentation for String#unpack: C | Fixnum | extract a character as an unsigned integer U | Integer | UTF-8 characters as unsigned integers unpack('C*') does indeed give me what I want... Cheers, Greg