0
How to sort an array string with any languages in Ruby?
- Chinese
- Japanese
- ...
I had figure out some gems to sort an array str
- sort_alphabetical https://github.com/grosser/sort_alphabetical
- use ICU https://github.com/fantasticfears/ffi-icu
But the result return that seem wrong.
Example: string array
array = ["合同会社スパシーバ", "合同会社ケイ・ティ・エム", "合同会社あぶみ設備", "合同会社日新HS", "合同会社そ・わ・か", "合同会社ENLIGHTEN", "合同会社ワイズ", "合同会社たまや", "合同会社アップウエスト", "株式会社安谷総合管理", "中信総合リース株式会社"]
solution 1:
array.sort_alphabetical #=>
["エクスボックスパートナーズ合同会社", "コンプ合同会社", "合同会社ENLIGHTEN", "合同会社T−nosuke", "合同会社あぶみ設備", "合同会社アップウエスト", "合同会社アーキスタイル", "建築総合センター", "御坊市日高川町中学校組合", "株式会社安谷総合管理", "角虎ネット合同会社"]
solution 2:
collator = ICU::Collation::Collator.new("ja")
array.sort! { |a,b| collator.compare(a, b) } #=>
["エクスボックスパートナーズ合同会社", "コンプ合同会社", "角虎ネット合同会社", "株式会社安谷総合管理", "建築総合センター", "御坊市日高川町中学校組合", "合同会社ENLIGHTEN", "合同会社T−nosuke", "合同会社アーキスタイル", "合同会社アップウエスト", "合同会社あぶみ設備"]
it look wrong, i see
updated at 16:01
My problem now is gem ffi-icu can sort
- alphabet hiragana => OK
- alphabet kanji => Faile (so mess)
Bạn có thể cho ví dụ một mảng không? Mảng string mà bạn cần search có các phần tử như thế nào?
@tranxuanthang updated