From: "David A. Black" Date: 2009-10-27T20:01:01+09:00 Subject: Re: array question --1926193751-770080717-1256641248=:11234 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-770080717-1256641248=:11234" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-770080717-1256641248=:11234 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8BIT Hi -- On Tue, 27 Oct 2009, Phrogz wrote: > On Oct 26, 6:46�pm, "David A. Black" wrote: >>> need to separate strings into arrays for a program that I am making. >>> For example, if I have the string 'abc', I'll want to make it into the >>> array ['a', 'b', 'c']. �Is there any way to do this? �I am using version >>> 1.8.6, by the way. �All help is welcome. >> >> The method you want is String#split: >> >> � �'abc'.split(//) �# => ['a', 'b', 'c'] > > > Here are two other techniques, just for fun: > > all_characters = "abc".scan(/./) That won't include newline characters, though, unless you use the /m modifier. > all_characters=[] > "abc".each_char{ |x| all_characters.push(x) } :-) Actually in 1.9 you could do: str.chars.to_a but he's using 1.8.6. David -- The Ruby training with D. Black, G. Brown, J.McAnally Compleat Jan 22-23, 2010, Tampa, FL Rubyist http://www.thecompleatrubyist.com David A. Black/Ruby Power and Light, LLC (http://www.rubypal.com) --1926193751-770080717-1256641248=:11234-- --1926193751-770080717-1256641248=:11234--