creatorvalet

Sort lines alphabetically

Alphabetical sorting that puts item2 before item10, the way you expect.

Runs in your browser0 bytes uploaded
№ 3933waiting

Nothing at the counter yet.

Why item10 usually comes before item2

Plain alphabetical sorting compares one character at a time. It reaches the1 in item10 and the 2 in item2, sees that 1 comes before 2, and stops there. The rest of the number never gets looked at.

That is technically correct string ordering and almost never what anyone wants. It is why file managers used to list chapter1, chapter10,chapter11, chapter2 — and why every operating system eventually added natural sorting instead.

Natural ordering reads runs of digits as numbers rather than as characters, soitem2 sorts before item10. It is on by default here. Turn it off if you specifically need raw string order — comparing against a database index, for example, where the database is doing plain comparison and you need to match it.

Sort lines in non-English alphabets

Sorting by raw character codes puts Swedish å, ä andö somewhere after z — which happens to be correct for Swedish, and entirely by accident. It also puts é in a position no French speaker would expect, and Ø nowhere near where a Dane would look.

This tool uses locale-aware comparison rather than character codes. Accented letters sort next to their base letter where that is the convention, and Swedish letters sort at the end of the alphabet where they belong.

Case and capitalisation

Sorting is case-insensitive, so apple and Apple land next to each other rather than in two separate blocks. Raw character-code sorting puts every capitalised word before every lowercase one, which splits an alphabetical list into two alphabetical lists — technically sorted, practically useless.

What happens to blank lines

They are removed. A sorted list beginning with fourteen empty lines is not a useful result, and blank lines carry no ordering information. Lines are trimmed of leading and trailing whitespace before comparison, so a stray space from a copy-paste does not push a line to the top.

Questions

Why does item10 usually come before item2?

Plain alphabetical sorting compares character by character, and the character "1" comes before "2". Natural sorting reads runs of digits as numbers instead, which puts item2 first. It is on by default here.

Does it handle å, ä and ö?

Yes. Sorting uses the browser locale comparison rather than raw character codes, so Swedish letters sort after z rather than in the middle of the Latin range.