title: Sorting strings containing numbers in a user friendly way
body: <p>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:</p>
  
  <p>Track1.mp3<br/>
  Track2.mp3<br/>
  Track10.mp3<br/>
  Track20.mp3<br/></p>
  
  <p>I think that those names are compared (during sorting) based on letters and by numbers separately.</p>
  
  <p>On the other hand, the following is the same list sorted in a standard way:<br/>
  Track1.mp3<br/>
  Track10.mp3<br/>
  Track2.mp3<br/>
  Track20.mp3<br/></p>
  
  <p>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.</p>
  
  <p>To give you an example, I'll compare "Track10" and "Track2" strings this way:<br/>
  1) read characters while they are equal and while they are letters: "Track", "Track"<br/>
  2) if a digit is found, read all following digits: "10", "2"<br/>
  2a) if they are equal, go to 1 or else finish<br/>
  Ten is greater than two, so "Track10" is greater than "Track2"<br/></p>
  
  <p>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).</p>
  
  <p>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?</p>
  
  <p>Thanks a lot!<br/>
  Mariusz</p>