On 12/20/06, Josselin <josselin / wanadoo.fr> wrote:
[...]
>
> ['Paris 1'  , 'Paris 10' , 'Paris 11' , .....  'Paris 19' , 'Paris 2' ,
>  'Paris 20' , 'Paris 3' , .... 'Paris 9' ]
>
> is there any way to sort this array and get :
>
> ['Paris 1'  , 'Paris 2' , 'Paris 3' , .... 'Paris 9' , 'Paris 10' ,
> 'Paris 11' , .....  'Paris 19' , 'Paris 20' ]
>
> which seems betetr in a list... ;-))
>

I have had a similar problem several times (but not with Paris :), and
I wrote a general utility function like this:

  def sort_numbers_numerically(arr)
      arr.sort_by do |str|
          i = 0
          str.split(/(\d+)/).map do |part|
              i += 1
              i % 2 == 0 ? part.to_i : part
          end
      end
  end

It is of course very similar to the previously proposed solutions, but
is more general in that it sorts strings with several numbers in them,
treating each number "numerically" (one extreme example could be
IP-numbers).

/johan