[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to pack an integer array to string?

Liang He

10/11/2007 4:42:00 PM

I want to pack an array such as [1,2,3,4]
to "1234", instead of \001\002\003\004, how to do that?
--
Posted via http://www.ruby-....

4 Answers

Jeremy Hinegardner

10/11/2007 5:29:00 PM

0

On Fri, Oct 12, 2007 at 01:42:15AM +0900, Liang He wrote:
> I want to pack an array such as [1,2,3,4]
> to "1234", instead of \001\002\003\004, how to do that?

% irb
>> x = [1,2,3,4]
=> [1, 2, 3, 4]
>> x.join('')
=> "1234"
>>

enjoy,

-jeremy

--
========================================================================
Jeremy Hinegardner jeremy@hinegardner.org


John Woods

10/11/2007 5:32:00 PM

0

I just tried this in irb:

irb(main):112:0> [1,2,3,4].to_s
=> "1234"


-----Original Message-----
From: Liang He
Sent: 10/11/2007 09:42 AM
> I want to pack an array such as [1,2,3,4]
> to "1234", instead of \001\002\003\004, how to do that?
>

Liang He

10/12/2007 2:56:00 AM

0

I just put eyes on 'pack', not aware that so many workarounds.
Thanks guys!

--
Posted via http://www.ruby-....

Peña, Botp

10/15/2007 1:01:00 AM

0

From: John Woods [mailto:jqwoods@gmail.com]
# I just tried this in irb:
# irb(main):112:0> [1,2,3,4].to_s
# => "1234"

careful w that.

C:\family\ruby>ruby -e "puts RUBY_VERSION;puts [1,2,3,4].to_s"
1.8.6
1234

C:\ruby1.9\bin>ruby -e "puts RUBY_VERSION;puts [1,2,3,4].to_s"
1.9.0
[1, 2, 3, 4]

kind regards -botp