Alphabetically order a list?
If I have a string that is a list of commands (or any kind of strings for that matter) separated by spaces, for example, like:
"/jill /bob /foo /ahhh /bomb /picklesurprise"
Is there a function, or one that can easily be made, to reorganize it alphabetically, so that the above becomes:
"/ahhh /bob /bomb /jill /picklesurprise"
? Or is it possible to do this if the list is in some other kind of format?
"/jill /bob /foo /ahhh /bomb /picklesurprise"
Is there a function, or one that can easily be made, to reorganize it alphabetically, so that the above becomes:
"/ahhh /bob /bomb /jill /picklesurprise"
? Or is it possible to do this if the list is in some other kind of format?
Comments
Here's a quick (not heavily tested) function that should do the trick for you.
function insertionSort(%list) { %len = getWordCount(%list); for (%i = 1; %i < %len; %i++) { %value = getWord(%list, %i); %j = %i - 1; for (%j = %i - 1; %j >= 0 && strcmp((%w = getWord(%list, %j)), %value) > 0; %j--) %list = setWord(%list, %j+1, %w); %list = setWord(%list, %j + 1, %value); } return %list; }