Word by word or letter by letter
Two lists of the same names, both in alphabetic order, both correct, and still different. The split comes from one question: does a space count?
- Word by word treats a space as smaller than any letter. Every name starting with the word New files before any name where New runs straight into more letters.
- Letter by letter deletes spaces and hyphens first, then compares. New York becomes NewYork and lands after Newcastle.
| Position | Word by word | Letter by letter |
|---|---|---|
| 1 | New Delhi | Newark |
| 2 | New York | Newcastle |
| 3 | Newark | New Delhi |
| 4 | Newcastle | New York |
Library catalogs and phone directories file word by word. Dictionaries file letter by letter, because a dictionary reader looks up a spelling, not a phrase. The Chicago Manual of Style describes both systems for book indexes. Pick one rule per list and stick with the choice. A glossary where half the entries follow each rule reads as broken, even when every pair looks fine on its own.
Why a script puts Zebra ahead of apple
Computers store each character as a number. Capital A through Z sit at 65 to 90 and small a through z at 97 to 122, so every capital outranks every small letter. Sort by those raw numbers and the list comes out like this:
Banana
Zebra
apple
cherry
JavaScript's plain array.sort(), Python's sorted() on strings, and the Unix sort command under LC_ALL=C all compare raw code points. Pick Code point under Capital letters to predict their output before your script runs. The mode also shows a second side effect: Ålesund and Århus fall to the bottom of the sample, below every plain letter, since Å sits at 197.
Capitals first is the gentler option. Apple and apple stay next to each other, with the capitalized one first, and both still file before banana.
The Hague files under H
Catalogers drop a leading article before filing a title, so The Great Gatsby sits under G. Library records encode the rule directly: the MARC title field carries a count of non-filing characters, 4 for "The ". With Skip a leading The, A or An on, the tool sorts on the words after the article and keeps the full title in the output.
The option covers English articles only. Los Angeles, El Paso and Le Havre stay under L and E. Switch the option off for lists where the article is part of what people search for, such as band names in a record shop.
Chapter 2 before Chapter 10
Compared one character at a time, "Chapter 10" beats "Chapter 2" because 1 comes before 2. Natural number order reads each run of digits as a whole number instead.
| Natural order on | Natural order off |
|---|---|
| Chapter 1 | Chapter 1 |
| Chapter 2 | Chapter 10 |
| Chapter 10 | Chapter 2 |
img2.png | img12.png |
img12.png | img2.png |
Decimals break the trick. In 1.25 and 1.5, the digits after the point form separate runs, 25 and 5, so 1.5 lands first. For prices, scores or measurements, the numeric list sorter reads the full value.
Å, Ñ and letters past Z
The English alphabet folds accented letters into the base letter. Zürich files with Z, São Paulo with S, and Ålesund opens the sample list under A. Other languages give some of those letters their own slot:
- Swedish adds Å, Ä and Ö after Z. Ålesund and Århus move to the end.
- Norwegian and Danish add Æ, Ø and Å after Z.
- Spanish puts Ñ between N and O, so ñandú follows nube.
- German uses dictionary order, where ä files with a. Phone-book order, which spells ä as ae, is not offered.
Choose the alphabet your readers use, not the one the item names come from. A Swedish author index files Ålesund after Z, while an English atlas index files Ålesund under A. The letter strip under the result follows the alphabet you pick, so Swedish shows Å, Ä and Ö as extra tiles.
Reading the grouped view
Grouped by letter puts a heading over each first letter, the layout of a glossary or a back-of-book index. The strip under the result marks letters with entries in dark tiles and empty letters in pale ones. Click a dark tile to jump to its group. Copy result copies whichever view is open, headings included.
Headings come from the sort key, not the raw text. With articles skipped, The Hague sits under H. Digits group under #. In Code point mode a letter heading appears twice when capitals and small letters split apart, a quick visual reason to keep the mode for code and not for readers.
Where this tool stops
- Names sort as typed. Mary Ellen Carter files under M. For a name index, enter surname first: Carter, Mary Ellen.
- Mc and Mac sort by spelling. The result reads MacDonald, Mack, McAdams, McDonald. Older library rules filed every Mc as Mac. This tool does not.
- Abbreviations stay abbreviated. St. Louis and Saint Louis land in different places. Expand them before sorting if they belong together.
- Roman numerals sort as letters. Henry IV, Henry IX, Henry V, Henry VIII is the output, not the order of reign. Type 4, 5, 8, 9 with natural order on for regnal lists.
- Size. In testing on a laptop, 50,000 lines sorted in under 0.2 seconds and 200,000 in about one second. The text box gets sluggish before the sort does. Past 20,000 items the result waits for a pause in your typing.
- Whole items only. Each line or comma-separated item moves as one block. To strip blank lines and repeats in one pass with numeric sorting too, Cleaner Sort Text Lines fits better.