From: "Guy N. Hurst" Date: 2001-02-25T12:42:32+09:00 Subject: [ruby-talk:11510] Re: Sorting Kevin Smith wrote: > ... > > This works: > > strings = [ "Name 300", "Name 1", "Name 10", > "Name 2" ] > b = strings.sort do | a, b | > a.split <=> b.split > end > p strings > p b > But what about for this? strings=["Name 100","Name 11","Name 10","Name 1", "Name 101","Name 22","Name 200","Name 2"] your code generates: ["Name 1", "Name 10", "Name 100", "Name 101", "Name 11", "Name 2", "Name 200", "Name 22"] If I add "[1]to_i" after each split, then it does things better... b = strings.sort do | a, b | a.split[1].to_i <=> b.split[1].to_i end p b result: ["Name 1", "Name 2", "Name 10", "Name 11", "Name 22", "Name 100", "Name 101", "Name 200"] Of course, this is assuming there is a second element in the array after the split, and that it is convertible to an integer. Guy N. Hurst -- HurstLinks Web Development http://www.hurstlinks.com/ Norfolk, VA 23510 (757)623-9688 FAX 623-0433 PHP/MySQL - Ruby/Perl - HTML/Javascript