From: 7stud -- Date: 2009-04-27T10:08:33+09:00 Subject: Re: How to parse a "line"? Martin Sharon wrote: > Thank you Todd, but the number of the keywords are dynamic. > > and the array size is not fixed until program reads the first keywords > of the input line. > Explain why these solutions won't work for you: strs = ["6 toyota bmw honda GM Ford", "3 tokyo newyork paris"] strs.each do |str| puts "1) split with subscripts:" p str.split()[1..-1] puts "2) split with parallel assignment:" first, *therest = str.split() p therest puts end --output:-- 1) split with subscripts: ["toyota", "bmw", "honda", "GM", "Ford"] 2) split with parallel assignment: ["toyota", "bmw", "honda", "GM", "Ford"] 1) split with subscripts: ["tokyo", "newyork", "paris"] 2) split with parallel assignment: ["tokyo", "newyork", "paris"] -- Posted via http://www.ruby-forum.com/.