Text Sorter: How It Works
Sorting a list looks trivial until the data contains numbers, mixed case, accented characters or leading whitespace. Then the default alphabetical order produces results that are technically correct and obviously wrong — this page explains why, and which option fixes each case.
Why 10 sorts before 9
Standard alphabetical sorting compares character by character. '10' and '9' are compared at the first character: '1' comes before '9', so '10' wins — regardless of the numbers' actual values.
| Alphabetical | Natural |
|---|---|
| file1, file10, file11, file2, file20, file3 | file1, file2, file3, file10, file11, file20 |
Natural sort recognises digit runs and compares them numerically, which is what people expect from filenames, version numbers and anything with an embedded index. It is the right default for most human-facing lists.
Case sensitivity
A case-sensitive sort orders by character code, which places every uppercase letter before every lowercase one: Apple, Banana, apple, banana. Case-insensitive sorting produces apple, Apple, banana, Banana, which is nearly always what a person wants for names, tags and titles.
Accents and locale
Sorting is language-dependent, and character codes do not reflect any language's alphabet. In Swedish, å, ä and ö come after z. In German phone books, ä sorts as 'ae'. In Spanish, ñ has its own position after n. A byte-order sort places every accented character after every unaccented one, which is wrong in every one of these languages.
Locale-aware sorting — Intl.Collator in JavaScript, ICU collation in most databases — handles this. If you are sorting names for people who will read them, it matters.
The invisible-whitespace problem
A line with a leading space sorts before everything, because the space character precedes every letter. Data copied from spreadsheets or PDFs routinely carries leading and trailing whitespace, and the result is a sorted list with a handful of entries stranded at the top for no visible reason. Trim before sorting, always.
Stability
A stable sort preserves the original relative order of items that compare equal. This matters when sorting by multiple criteria: to sort by department and then by name, sort by name first and then by department with a stable algorithm, and the name order survives within each department. With an unstable sort it does not, and the result looks arbitrary.
Other useful orderings
| Order | Use for |
|---|---|
| By length | Finding outliers, truncated entries, empty rows |
| Reverse | Most recent first, descending values |
| Random / shuffle | Sampling, fair ordering, removing position bias |
| By last word | Sorting full names by surname |
Practical sequence
- Trim whitespace.
- Decide whether blank lines are removed or kept.
- Choose natural ordering if the data contains numbers.
- Choose case-insensitive unless case is meaningful.
- Deduplicate before or after depending on whether duplicates should be counted.
Sorting runs entirely in your browser here, which matters when the list is customer names, email addresses or internal identifiers — data that should not be pasted into a server-side tool.