I am saving some files in document directory through my app using custom naming as “file1.format” ,”file2.format” and so on.Later I fetch these files in an Array and printing them in a loop then they are coming in sorted form but the problem arises when I store “file10.format” and so on. After this the result comes is some what unexpected. As after saving 10th file the output comes like
file1.foramt
file10.format
file2.format
.
.
file6.format
file61.format
file7.format
I don’t know why sorting take all 1s or 2s on one place as shown above while it is expected that 10 should just comes after 9 not after 1.I used all kind of sorting but the result is coming same all time.
If you want to sort file names “as the Finder does”, use
localizedStandardCompare. In particular, numbers in the strings are sorted according to their numeric value:Output: