On Sun, Apr 26, 2009 at 4:11 PM, Robert Dober <robert.dober / gmail.com> wrote: > On Sun, Apr 26, 2009 at 10:56 PM, James Gray <james / grayproductions.net> 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 I like... (items = my_item_list).split.shift Both you and I have examples, though, that do not return what the statement using [1..-1] does. Mine, returns 3. Ah well, "items" exists, though :) Todd