[MacRuby-devel] convert array into a string

Laurent Sansonetti lsansonetti at apple.com
Mon Jan 10 13:29:38 PST 2011


On Jan 10, 2011, at 1:22 PM, Caio Chassot wrote:

> On 2011-01-10, at 19:19 , Laurent Sansonetti wrote:
>> 
>> Assuming your array contains ASCII fixnum representation of characters, messaging #pack('c*') on it should give you a string object back.
>> 
>> I dislike this method, but here I don't see a better choice.
> 
> numbers = [65, 195, 169]
> s = numbers.map(&:chr).join
> 
> you may want to force the string to be treated as UTF-8.
> 
> s.force_encoding('UTF-8')

That's much better indeed!

Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20110110/3fe3ffa8/attachment.html>


More information about the MacRuby-devel mailing list