From: Gary Wright Date: 2007-02-25T05:50:18+09:00 Subject: Re: using step backward ? On Feb 24, 2007, at 1:00 PM, Josselin wrote: > I have an array myArray = ["22", "31", "56", "89", "47"] > > I would like to produce a string like : "22#31#56#89>47<" where > the last item must be : >last_item< > > case 1 item : ["22"] => ">22<" > case 2 items : ["22", "31"] => "22#>31<" > .. > case n items : ["22", "31", "56", .........., "89", "47"] => > "22#31#56#...........#89>47<" I'm assuming you have a typo in that last case and want the string to end with: "#89#>47<". It isn't clear how you would want an empty list formatted but here is one possibility: $ cat format.rb def format(list) list[0..-2].push(">#{list.last}<").join('#') end puts format([]) puts format(%w{22}) puts format(%w{22 31}) puts format(%w{22 31 56}) $ ruby format.rb >< >22< 22#>31< 22#31#>56< Gary Wright