Forum: Ruby on Rails sort array of strings with čšž

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D77663a5995b5538aa0bc62e6940e241?d=identicon&s=25 sine serz (sineserz)
on 2008-11-07 09:58
hi,

I have problems with sorting array of strings with special characters (č
š ž),


%w"abcčdesšuvzž".sort => "abcdesuvzčšž"

the right order should be č after c, š after s and ž after z.

I write my own sort method:

sort_order = ['a','b','c','č','d','e','f','g','h','i','j','k','l',
    'm','n','o','q','p','r','s','š','t','u','v','w','z','ž','x','y']
user_items.sort_by {|u| sort_order.index(u.name.first)}

But it only works, if im sorting by first character.

How can i sort the whole words with right order?

example: %w"audi, bmw 320i, ,bmw 320d, seat, Å¡koda, ...".


thanks

sergej
This topic is locked and can not be replied to.