How to pack an integer array to string?

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-forum.com/.

$ ri Array#join
------------------------------------------------------------- Array#join
     array.join(sep=$,) -> str

···

-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Liang He
Sent: Thursday, October 11, 2007 9:42 AM
To: ruby-talk ML
Subject: how to pack an integer array to string?

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-forum.com/\.

------------------------------------------------------------------------
     Returns a string created by converting each element of the array to
     a string, separated by _sep_.

        [ "a", "b", "c" ].join #=> "abc"
        [ "a", "b", "c" ].join("-") #=> "a-b-c"

$ irb
irb(main):001:0> [1,2,3,4].join
=> "1234"

HTH,

Felix

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

···

On Fri, Oct 12, 2007 at 01:42:15AM +0900, Liang He wrote:

--

Jeremy Hinegardner jeremy@hinegardner.org

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?

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

···

--
Posted via http://www.ruby-forum.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

···

From: John Woods [mailto:jqwoods@gmail.com]