From: 7stud -- Date: 2009-09-17T02:53:53+09:00 Subject: Re: string to array Re BR wrote: > Hello all, > > I have a string "apple-orange-grape". I need to create a array that will > look like > ["apple-orange-grape","orange-grape","grape"] > > thanks 1) str = "apple-orange-grape" results = [] results << str pos = 0 while pos = str.index("-", pos) pos += 1 results << str[pos..-1] end p results --output:-- ["apple-orange-grape", "orange-grape", "grape"] 2) str = "apple-orange-grape" results = [str] str.scan(/-/) do |match| results << $' end p results --output:-- ["apple-orange-grape", "orange-grape", "grape"] Uhg. Are there alternate names for the perl $ variables? I thought there were, but I can't find them anywhere. -- Posted via http://www.ruby-forum.com/.