Compare Strings in a Language
The new function AlphabeticOrder allows strings to be compared in terms of the alphabetic order associated to a language.
AlphabeticOrder returns 1 when the first string should appear before the second one, 0 if they are equivalent, and −1 when they are reversed.
In[1]:=
![Click for copyable input](assets.en/compare-strings-in-a-language/In_18.png)
AlphabeticOrder["z", "å", Entity["Language", "Swedish"]]
Out[1]=
![](assets.en/compare-strings-in-a-language/O_12.png)
The results from AlphabeticOrder and Order may be different for non-English languages.
In[2]:=
![Click for copyable input](assets.en/compare-strings-in-a-language/In_19.png)
{Order["італьянская", "японская"],
AlphabeticOrder["італьянская", "японская", "Belarusian"]}
Out[2]=
![](assets.en/compare-strings-in-a-language/O_13.png)
The IgnoreDiacritics option allows flexible string comparisons.
In[3]:=
![Click for copyable input](assets.en/compare-strings-in-a-language/In_20.png)
AlphabeticOrder["como", "cómo", Entity["Language", "Spanish"],
IgnoreDiacritics -> True]
Out[3]=
![](assets.en/compare-strings-in-a-language/O_14.png)
This option does not override basic language rules. For example, one letter may be considered as a diacritic in one language but a basic letter in another language.
In[4]:=
![Click for copyable input](assets.en/compare-strings-in-a-language/In_21.png)
{AlphabeticOrder["ñandú", "nandu", Entity["Language", "Spanish"],
IgnoreDiacritics -> True],
AlphabeticOrder["ñandú", "nandu", Entity["Language", "English"],
IgnoreDiacritics -> True]}
Out[4]=
![](assets.en/compare-strings-in-a-language/O_15.png)
The function AlphabeticSort sorts using AlphabeticOrder as ordering function.
In[5]:=
![Click for copyable input](assets.en/compare-strings-in-a-language/In_22.png)
AlphabeticSort[{"アメリカ合衆国", "日本", "イギリス", "ペルー", "スウェーデン", "インド"},
Entity["Language", "Japanese"]]
Out[5]=
![](assets.en/compare-strings-in-a-language/O_16.png)