Spaces When Alphabetizing
Should you count them?
Usually, yes.
We don’t normally encounter this problem because it’s not common (outside of computing) to order multi-word phrases.
A space is usually considered to come before all other letters, when sorting words into alphabetical order (see below for a specific example). Essentially, you sort by first word. If the first word is the same, you include the second word, and so on.
However, this is not absolute. In some cases (dictionaries, for instance), spaces will be removed or “collapsed,” and the words ordered based on what’s left.
Why I Looked It Up
When viewing the alphabetical list in my library, I found this oddity:
- Bigger Secrets
- Big Secrets
That didn’t seem right – I felt like “Big Secrets” should come first because “Big” should come before “Bigger.” It turns out I was removing the spaces, so the two titles look like this to the computer:
- BiggerSecrets
- BigSecrets
The first two letters are the same, but without the space, the third and fourth letters are:
- gg
- gS
And that explains the sorting. I changed the code to keep the space, and the sorting reversed.