Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 245331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:04:47+00:00 2026-05-11T21:04:47+00:00

Being used to the standard way of sorting strings, I was surprised when I

  • 0

Being used to the standard way of sorting strings, I was surprised when I noticed that Windows sorts files by their names in a kind of advanced way. Let me give you an example:

Track1.mp3
Track2.mp3
Track10.mp3
Track20.mp3

I think that those names are compared (during sorting) based on letters and by numbers separately.

On the other hand, the following is the same list sorted in a standard way:
Track1.mp3
Track10.mp3
Track2.mp3
Track20.mp3

I would like to create a comparing alogorithm in Delphi that would let me sort strings in the same way. At first I thought it would be enough to compare consecutive characters of two strings while they are letters. When a digit would be found at some position of both the strings, I would read all digits following them to form a number and then compare the numbers.

To give you an example, I’ll compare “Track10” and “Track2” strings this way:
1) read characters while they are equal and while they are letters: “Track”, “Track”
2) if a digit is found, read all following digits: “10”, “2”
2a) if they are equal, go to 1 or else finish
Ten is greater than two, so “Track10” is greater than “Track2”

It had seemed that everything would be all right until I noticed, during my tests, that Windows considered “Track010” lower than “Track10”, while I thought the first one was greater as it was longer (not mentioning that according to my algorithm both the strings would be equal, which is wrong).

Could you provide me with the idea how exactly Windows sorts files by names or maybe you have a ready-to-use algorithm (in any programming language) that I could base on?

Thanks a lot!
Mariusz

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:04:47+00:00Added an answer on May 11, 2026 at 9:04 pm

    Jeff wrote up an article about this on Coding Horror. This is called natural sorting, where you effectively treat a group of digits as a single “character”. There are implementations out there in every language under the sun, but strangely it’s not usually built-in to most languages’ standard libraries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: m4 is being used so _ prefixed strings are expanded (m4 is a
I am building a Windows dialog box that has the standard 'OK' and 'Cancel'
I have an SSAS 2008 cube that is being used to house end of
Not being used to php, I'm facing an issue with accessing arrays and its
When GWT UIBinder being used by default, a pair of java source and UI
I have three tables being used for this problem: songs, blacklist, and whitelist. The
A timer is being used in my C# application to determine if an expected
A quartz scheduler is being used in an Application I am working on. A
The following code is being used to disable a Submit button once it has
I have a class being used in node.js, and I want to pass various

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.