From: Robert Dober Date: 2009-04-27T06:11:44+09:00 Subject: Re: How to parse a "line"? On Sun, Apr 26, 2009 at 10:56 PM, James Gray wrote: > On Apr 26, 2009, at 3:48 PM, Martin Sharon wrote: > >> Hi there: >> >> I have a line, the format is like this >> "num_of_item item1 item2...item_n" for example >> >> "3 Tokyo Newyork Paris" >> >> I want ruby parse this format, extract these keywords and save them in >> an array. >> I googled and search many forums, but can't find any matches. >> >> Would anyone give me any ideas?? > > If you just need to bust up the words via the spaces, this should probably > work for you: > >>> items = "3 Tokyo Newyork Paris".split[1..-1] > => ["Tokyo", "Newyork", "Paris"] This is another opportunity to show Ruby's versatile style, e.g. functional _, *items = "3 .a b c".split R.