After sorting my customer names, a few names jumped to the top out of order; why?

Those lines start with a space you cannot see, and a line that starts with a space or a symbol sorts before every letter. Turn on «Ignore spaces at the start of a line when comparing» and the names are ordered from their first visible letter; if you want the spaces themselves gone, clean them with the whitespace tool.

Published · 3 min read

Where the spaces come from

Nobody types a space before a name on purpose. It arrives from an order form where the customer hit the space bar first, a spreadsheet cell with padding, or a column copied out of a PDF or a WhatsApp chat. On screen «Sara» and « Sara» look identical. To the sorter they are different texts: one starts with S, the other with a space.

The ordering rules put spaces, punctuation and symbols before digits, and digits before letters. So any name that begins with a space rises to the top, whatever its first letter is.

An example from the tool

Four Arabic names, two of them with leading spaces: « محمد» with two spaces, « سارة» with one, then «أحمد» and «خالد» with none. With Arabic rules and ascending order the result was محمد, سارة, أحمد, خالد. Both padded names went to the top, and محمد came before سارة because its line starts with two spaces.

With «Ignore spaces at the start of a line» turned on, the result was أحمد, خالد, سارة, محمد: the correct alphabetical order.

The option changes the comparison only

This is the part people miss: the option does not delete the spaces. It skips them while comparing, then prints each line exactly as it was, so « سارة» still carries its space in the result. That is enough for a list you only need to read. If the names are going onto shipping labels or into a system that matches text exactly, the leftover space can cause a different problem, and then you want it removed for real.

  1. Sorting only: paste the list into the Line sorter, tick «Ignore spaces at the start of a line when comparing», and copy the result.
  2. Clean names: run the list through the Whitespace cleaner first to trim the edges of every line, then sort without needing the option.

Other reasons names jump

  • A name that starts with punctuation, such as a «-» or «*» left over from a copied bullet list. That is a symbol, not a space, so the option does not skip it. Delete the mark first.
  • An English name among Arabic ones: with Arabic rules it goes to the end of the list, with English rules to the start. Pick the rules under «Sorting rules».
  • Names that start with numbers, such as an order number before the name: digits come before letters, which is expected rather than a fault.

Common questions

Does the option also ignore spaces inside a name?

No, only the ones at the start of the line. The space between a first name and a family name is still part of the comparison.

Does it affect duplicate removal?

Yes. With both options on, « Sara» and «Sara» count as repeats and the first of the two is kept.