From: Stefan Rusterholz Date: 2007-11-01T19:19:08+09:00 Subject: Re: Sorting a string... Daniel Waite wrote: > I was porting a small Python script over to Ruby and realized Ruby does > not sort strings as I expected it would. > > 'cba'.sort # ["cba"] > > So I wrote this... If you just want to sort by byte-value (i.e. disregarding the possibility of a multibyte-encoding and ignoring umlauts etc.), you can do: str.unpack("C*").sort.pack("C*") It's about twice as fast as str.split(//).sort.join Regards Stefan -- Posted via http://www.ruby-forum.com/.