From: gabriele renzi Date: 2004-06-05T19:58:39+09:00 Subject: Re: Chars in Ruby il Sat, 05 Jun 2004 10:40:45 GMT, "Georgy" ha scritto:: >Hi, >So we can think of a "char" as a single element of a string. >Now, having that an integer is a single element of an array, >we'd like to have functions/expressions for converting arrays >of integers and strings back and forth. > >Array to String: [97,98,99].map{|e|e.chr}.join --> "abc" >String to Array: "abc" ????????????? --> [97,98,99] > >I've found that this function can do it: > >def s2a(s); r=[]; s.each_byte {|b| r<s2a("abc") --> [97,98,99] > >But can it be an expression w/o a function or with a shorter >"more elegant" function, w/o accumulator r? use pack() and unpack()