From: William James Date: 2006-07-22T06:15:09+09:00 Subject: Re: splitting a string separated by CRLF into array dominique.plante@gmail.com wrote: > How can I get the array > > ["hello", "world", "123"] > > from the string > > "hello\r\nworld\r\n123" > > Thanks! > Dominique irb(main):001:0> "hello\r\nworld\r\n123".split => ["hello", "world", "123"] irb(main):011:0> "hello\r\nworld\r\n123".split(/\s+/) => ["hello", "world", "123"] irb(main):012:0> "hello\r\nworld\r\n123".scan(/\S+/) => ["hello", "world", "123"] irb(main):004:0> "hello\r\nworld\r\n123".to_a.map{|x|x.chomp} => ["hello", "world", "123"] irb(main):009:0> "hello\r\nworld\r\n123".inject([]){|a,b| a << b.chomp} => ["hello", "world", "123"]