Robert Klemme
11/9/2006 7:06:00 PM
Kero <kero@chello.single-dot.nl> wrote:
> On 2006-11-09, Chris Mueller <damngoodcoffee@gmail.com> wrote:
>> Hi,
>> i am new to ruby and i am wondering how many more ways (and what
>> ways) there are to do this:
>>
>> seperated_words = "hi, you, guys"
>> words_array = seperated_words.split(",")
>> for i in 0 ... words_array.length
>> words_array[i] = words_array[i].strip
>> end
>>
>> i suppose there's a one-liner that you write before you can think
>> "ruby" doesn't it ???
>
> Functionally slightly different, but:
>
> words_array = separated_words.split(/, /)
And yet another one
irb(main):002:0> "hi, you, guys".split /\s*,\s*/
=> ["hi", "you", "guys"]
irb(main):003:0> "hi, you, guys".scan /\w+/
=> ["hi", "you", "guys"]
Cheers
robert