I have a problem with sorting an array which have strings with special Polish characters. My code looks like this:
我有一个问题,排序具有特殊波兰字符字符串的数组。我的代码是这样的:
["Łotwa", "Luksemburg", "Anglia"].sort_by{|x| ActiveSupport::Inflector.transliterate(x)}
and this code gives me the following result:
这个代码给了我以下的结果:
["Anglia", "Łotwa", "Luksemburg"]
but it should look like this:
但它应该是这样的:
["Anglia", "Luksemburg", "Łotwa"]
I tried to use these gems:
我试着使用这些宝石:
https://github.com/grosser/sort_alphabetical
https://github.com/jarib/ffi-icu
but they do not solve this problem. Problem is caused by the special Polish character "Ł"
.
但是他们并不能解决这个问题。问题是由波兰特殊字符“Ł”引起的。
1 个解决方案
#1
5
You can use string_case_pl gem:
可以使用string_case_pl gem:
require 'string_cmp_pl'
%w(Anglia Litwa Zanzibar Łotwa).sort
# => ["Anglia", "Litwa", "Łotwa", "Zanzibar"]
#1
5
You can use string_case_pl gem:
可以使用string_case_pl gem:
require 'string_cmp_pl'
%w(Anglia Litwa Zanzibar Łotwa).sort
# => ["Anglia", "Litwa", "Łotwa", "Zanzibar"]