Natural Sort (Part 2 of 3)

Before comparing strings we need to identify the text and the numeric parts in the string. The algorithm is very simple: iterate each character of the string, if we find a character that is not a digit, start a Characters chunk, if it’s a digit, create a new Number chunk. Process the next character. If it’s of the same kind than the previous one, then store it in a buffer and continue. If it’s not of the same type, then store the current buffer as a chunk part alongside it’s type, then create a new buffer and set the correct chunk type for it. Repeat the process until the end of the string.

Upside Down Arrays

Xojo® provides us with some interesting methods to manipulate arrays: Array, Join, Split, Append, IndexOf, Insert, Pop, Redim, Remove, Shuffle, Sort, SortWith, etc… You’ll find an exhaustive list in the Language Array category in Xojo®‘s Wiki. What you may notice is the lack of a method to reverse the order of the elements in the array. But this kind of manipulation shouldn’t be hard to code in Xojo®.