From: Josselin Date: 2007-02-25T08:30:12+09:00 Subject: Re: using step backward ? On 2007-02-24 21:50:18 +0100, Gary Wright said: > > 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<". YES .. sorry > 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< THAT's it......, very useful.. I put '#' and '>' '<' charcaters just to make it simple.. but the objective is to insert html tags to format correctly an output string... > > > > Gary Wright