---
title: "AlphabeticOrder"
language: "en"
type: "Symbol"
summary: "AlphabeticOrder[SubscriptBox[string, 1], SubscriptBox[string, 2]] gives 1 if SubscriptBox[string, 1] appears before SubscriptBox[string, 2] in alphabetical order, -1 if it is after, and 0 if it is identical. AlphabeticOrder[SubscriptBox[string, 1], SubscriptBox[string, 2], lang] uses an ordering suitable for the language lang. AlphabeticOrder[lang] represents an operator form that compares strings when applied to SubscriptBox[string, 1], SubscriptBox[string, 2]."
keywords: 
- lexicographic order
- collation order
- collation
- letter order
- alphabetic order
canonical_url: "https://reference.wolfram.com/language/ref/AlphabeticOrder.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "International Character Sets"
    link: "https://reference.wolfram.com/language/guide/InternationalCharacterSets.en.md"
  - 
    title: "Linguistic Data"
    link: "https://reference.wolfram.com/language/guide/LinguisticData.en.md"
  - 
    title: "Testing Expressions"
    link: "https://reference.wolfram.com/language/guide/TestingExpressions.en.md"
  - 
    title: "String Operations"
    link: "https://reference.wolfram.com/language/guide/StringOperations.en.md"
related_functions: 
  - 
    title: "AlphabeticSort"
    link: "https://reference.wolfram.com/language/ref/AlphabeticSort.en.md"
  - 
    title: "Order"
    link: "https://reference.wolfram.com/language/ref/Order.en.md"
  - 
    title: "LexicographicOrder"
    link: "https://reference.wolfram.com/language/ref/LexicographicOrder.en.md"
  - 
    title: "NumericalOrder"
    link: "https://reference.wolfram.com/language/ref/NumericalOrder.en.md"
  - 
    title: "Alphabet"
    link: "https://reference.wolfram.com/language/ref/Alphabet.en.md"
  - 
    title: "LanguageData"
    link: "https://reference.wolfram.com/language/ref/LanguageData.en.md"
---
# AlphabeticOrder

AlphabeticOrder["Subscript[string, 1]","Subscript[string, 2]"] 
gives 1 if "Subscript[string, 1]" appears before "Subscript[string, 2]" in alphabetical order, -1 if it is after, and 0 if it is identical. 
	AlphabeticOrder["Subscript[string, 1]","Subscript[string, 2]",lang]
uses an ordering suitable for the language lang.
	AlphabeticOrder[lang]
represents an operator form that compares strings when applied to "Subscript[string, 1]", "Subscript[string, 2]".

## Details and Options

* The language can be specified by a language standard name, as used in ``LanguageData``, or by a language entity. It can also be an alphabet specification, as used in ``Alphabet``.

* The default language is ``\$Language``.

* The following options can be given:

|                    |            |                                            |
| ------------------ | ---------- | ------------------------------------------ |
| CaseOrdering       | Automatic  | how to order upper vs. lower case          |
| IgnoreCase         | False      | whether to ignore case for ordering        |
| IgnoreDiacritics   | False      | whether to ignore diacritics for ordering  |
| IgnorePunctuation  | False      | whether to ignore punctuation for ordering |
| Language           | \$Language | what language or alphabet to assume        |

* If an explicit language is specified in ``AlphabeticOrder[…, lang]``, it overrides any setting for the ``Language`` option.

---

## Examples (23)

### Basic Examples (3)

Check the order of two characters:

```wl
In[1]:= AlphabeticOrder["a", "b"]

Out[1]= 1
```

---

Specify a language as the third argument:

```wl
In[1]:= AlphabeticOrder["ñ", "n", "Spanish"]

Out[1]= -1
```

---

When digraphs exist in a language, they are equivalent to corresponding pairs of ASCII characters:

```wl
In[1]:= AlphabeticOrder["ij", "ĳ", Entity["Language", "Dutch"]]

Out[1]= 0
```

### Scope (4)

``AlphabeticOrder`` operates over single characters or longer strings:

```wl
In[1]:= AlphabeticOrder["A", "c"]

Out[1]= 1

In[2]:= AlphabeticOrder["cat", "cart"]

Out[2]= -1
```

---

Use the operator form:

```wl
In[1]:= AlphabeticOrder[]["A", "c"]

Out[1]= 1
```

---

Specify a language in operator form:

```wl
In[1]:= AlphabeticOrder["Spanish"]["ñ", "n"]

Out[1]= -1
```

---

Use options in operator form:

```wl
In[1]:= AlphabeticOrder[CaseOrdering -> "UpperFirst"]["A", "a"]

Out[1]= 1
```

### Options (8)

#### CaseOrdering (2)

``CaseOrdering -> "LowerFirst"`` orders lowercase before uppercase letters. It is the default for most languages:

```wl
In[1]:= AlphabeticOrder["a", "A"] === AlphabeticOrder["a", "A", CaseOrdering -> "LowerFirst"]

Out[1]= True
```

---

``CaseOrdering -> "UpperFirst"`` orders uppercase before lowercase letters:

```wl
In[1]:= AlphabeticOrder["a", "A", "Danish"]

Out[1]= -1

In[2]:= AlphabeticOrder["a", "A", "Danish"] === AlphabeticOrder["a", "A", CaseOrdering -> "UpperFirst"]

Out[2]= True
```

#### IgnoreCase (2)

With ``IgnoreCase -> True``, comparisons are case insensitive:

```wl
In[1]:= AlphabeticOrder["a", "A", IgnoreCase -> #]& /@ {True, False}

Out[1]= {0, 1}
```

---

Equivalence between lower case and upper case can vary by language:

```wl
In[1]:= AlphabeticOrder["Turkish", IgnoreCase -> True]@@@{{"i", "I"}, {"ı", "I"}, {"i", "İ"}}

Out[1]= {-1, 0, 0}
```

#### IgnoreDiacritics (3)

With ``IgnoreDiacritics -> True``, comparisons are based only on basic letters from the alphabet:

```wl
In[1]:= AlphabeticOrder["a", "á", "Spanish", IgnoreDiacritics -> True]

Out[1]= 0

In[2]:= AlphabeticOrder["a", "á", "Spanish"]

Out[2]= 1
```

---

When characters with diacritics are considered to be a fundamental part of a given alphabet, ``IgnoreDiacritics`` will not affect those characters:

```wl
In[1]:= AlphabeticOrder["n", "ñ", "English", IgnoreDiacritics -> True]

Out[1]= 0

In[2]:= AlphabeticOrder["n", "ñ", "Spanish", IgnoreDiacritics -> True]

Out[2]= 1
```

---

The ``IgnoreDiacritics`` option can be mixed with any other option, such as ``IgnoreCase`` :

```wl
In[1]:= AlphabeticOrder["a", "Á", "Spanish", IgnoreDiacritics -> True, IgnoreCase -> True]

Out[1]= 0
```

#### IgnorePunctuation (1)

With ``IgnorePunctuation -> True``, punctuation characters are removed before comparing the strings:

```wl
In[1]:= AlphabeticOrder["Name-1", "Name.1", "Spanish", IgnorePunctuation -> True]

Out[1]= 0

In[2]:= AlphabeticOrder["it's", "its", "English", IgnorePunctuation -> False]

Out[2]= 1

In[3]:= AlphabeticOrder["it's", "its", "English", IgnorePunctuation -> True]

Out[3]= 0
```

### Applications (2)

Sort the Japanese names of countries with Wolfram offices:

```wl
In[1]:= Sort[{"アメリカ合衆国", "日本", "イギリス", "ペルー", "スウェーデン"}, AlphabeticOrder[Entity["Language", "Japanese"]][##] >= 0&]

Out[1]= {"アメリカ合衆国", "イギリス", "スウェーデン", "ペルー", "日本"}
```

---

When digraphs are part of a language, they will be ordered correctly (as in Slovak, where "ch" is after "h"):

```wl
In[1]:= AlphabeticOrder["Slovak"]@@@{{"chorvátčina", "hebrejčina"}, {"čeština", "hebrejčina"}}

Out[1]= {-1, 1}
```

### Properties & Relations (4)

Use the operator form of ``AlphabeticOrder`` to confirm that ``Alphabet`` of the same language is already ordered:

```wl
In[1]:= AlphabeticOrder["Spanish"]@@@Partition[Alphabet["Spanish"], 2, 1]

Out[1]= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
```

---

The results from ``AlphabeticOrder`` and ``Order`` may differ for non-English languages:

```wl
In[1]:= {Order["італьянская", "японская"], AlphabeticOrder["італьянская", "японская", "Belarusian"]}

Out[1]= {-1, 1}
```

---

For some languages, using ``IgnoreDiacritics`` may give a different result than applying ``RemoveDiacritics`` first:

```wl
In[1]:= AlphabeticOrder["z", "å", Entity["Language", "Swedish"], IgnoreDiacritics -> True]

Out[1]= 1

In[2]:= AlphabeticOrder["z", "å"//RemoveDiacritics, Entity["Language", "Swedish"]]

Out[2]= -1
```

---

``AlphabeticSort`` uses ``AlphabeticOrder`` as its ordering function:

```wl
In[1]:= AlphabeticSort[{"Arboga", "Alingsås", "Åmål", "Ängelholm", "Askersund", "Arvika"}, "Swedish"]

Out[1]= {"Alingsås", "Arboga", "Arvika", "Askersund", "Åmål", "Ängelholm"}

In[2]:= Sort[{"Arboga", "Alingsås", "Åmål", "Ängelholm", "Askersund", "Arvika"}, AlphabeticOrder["Swedish"][#1, #2] ≥ 0&]

Out[2]= {"Alingsås", "Arboga", "Arvika", "Askersund", "Åmål", "Ängelholm"}
```

### Possible Issues (1)

Different characters that represent the same letter in some languages are considered exact equivalents:

```wl
In[1]:= AlphabeticOrder["ţ", "ț", "Romanian"]

Out[1]= 0

In[2]:= AlphabeticOrder["ţ", "ț", "Latin"]

Out[2]= 1
```

### Neat Examples (1)

Find all Unicode characters considered equivalent to "a" without taking into account diacritics or case:

```wl
In[1]:= lettersA = Select[CharacterRange[1, 65535], AlphabeticOrder["a", #, IgnoreDiacritics -> True, IgnoreCase -> True] == 0&]

Out[1]= {"A", "a", "ª", "À", "Á", "Â", "Ã", "Ä", "Å", "à", "á", "â", "ã", "ä", "å", "Ā", "ā", "Ă", "ă", "Ą", "ą", "Ǎ", "ǎ", "Ǟ", "ǟ", "Ǡ", "ǡ", "Ǻ", "ǻ", "Ȁ", "ȁ", "Ȃ", "ȃ", "Ȧ", "ȧ", "ͣ", "ᴬ", "ᵃ", "ᷓ", "ᷲ", "Ḁ", "ḁ", "Ạ", "ạ", "Ả", "ả", "Ấ", "ấ", "Ầ", "ầ", "Ẩ", "ẩ", "Ẫ", "ẫ", "Ậ", "ậ", "Ắ", "ắ", "Ằ", "ằ", "Ẳ", "ẳ", "Ẵ", "ẵ", "Ặ", "ặ", "ₐ", "Å", "Ⓐ", "ⓐ", "Ꞛ", "ꞛ", "Ａ", "ａ"}
```

Sort alphabetically:

```wl
In[2]:= sortedA = Sort[lettersA, AlphabeticOrder[##] ≥ 0&]

Out[2]= {"a", "ａ", "ͣ", "ⓐ", "ª", "ᵃ", "ₐ", "A", "Ａ", "Ⓐ", "ᴬ", "á", "Á", "à", "À", "ă", "Ă", "ắ", "Ắ", "ằ", "Ằ", "ẵ", "Ẵ", "ẳ", "Ẳ", "â", "Â", "ấ", "Ấ", "ầ", "Ầ", "ẫ", "Ẫ", "ẩ", "Ẩ", "ǎ", "Ǎ", "å", "Å", "Å", "ǻ", "Ǻ", "ä", "ᷲ", "ꞛ", "Ä", "Ꞛ", "ǟ", "Ǟ", "ã", "Ã", "ȧ", "Ȧ", "ǡ", "Ǡ", "ą", "Ą", "ā", "Ā", "ả", "Ả", "ȁ", "Ȁ", "ȃ", "Ȃ", "ạ", "Ạ", "ặ", "Ặ", "ậ", "Ậ", "ḁ", "Ḁ", "ᷓ"}
```

Split by case:

```wl
In[3]:= GatherBy[sortedA, AlphabeticOrder[IgnoreDiacritics -> True, IgnoreCase -> False]["a", #]&]

Out[3]= {{"a", "ａ", "ͣ", "ⓐ", "ª", "ᵃ", "ₐ", "á", "à", "ă", "ắ", "ằ", "ẵ", "ẳ", "â", "ấ", "ầ", "ẫ", "ẩ", "ǎ", "å", "ǻ", "ä", "ᷲ", "ꞛ", "ǟ", "ã", "ȧ", "ǡ", "ą", "ā", "ả", "ȁ", "ȃ", "ạ", "ặ", "ậ", "ḁ", "ᷓ"}, {"A", "Ａ", "Ⓐ", "ᴬ", "Á", "À", "Ă", "Ắ", "Ằ", "Ẵ", "Ẳ", "Â", "Ấ", "Ầ", "Ẫ", "Ẩ", "Ǎ", "Å", "Å", "Ǻ", "Ä", "Ꞛ", "Ǟ", "Ã", "Ȧ", "Ǡ", "Ą", "Ā", "Ả", "Ȁ", "Ȃ", "Ạ", "Ặ", "Ậ", "Ḁ"}}
```

## See Also

* [`AlphabeticSort`](https://reference.wolfram.com/language/ref/AlphabeticSort.en.md)
* [`Order`](https://reference.wolfram.com/language/ref/Order.en.md)
* [`LexicographicOrder`](https://reference.wolfram.com/language/ref/LexicographicOrder.en.md)
* [`NumericalOrder`](https://reference.wolfram.com/language/ref/NumericalOrder.en.md)
* [`Alphabet`](https://reference.wolfram.com/language/ref/Alphabet.en.md)
* [`LanguageData`](https://reference.wolfram.com/language/ref/LanguageData.en.md)

## Related Guides

* [International Character Sets](https://reference.wolfram.com/language/guide/InternationalCharacterSets.en.md)
* [Linguistic Data](https://reference.wolfram.com/language/guide/LinguisticData.en.md)
* [Testing Expressions](https://reference.wolfram.com/language/guide/TestingExpressions.en.md)
* [String Operations](https://reference.wolfram.com/language/guide/StringOperations.en.md)

## History

* [Introduced in 2015 (10.3)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn103.en.md)