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?

Comments

  • Have you checked IRC functions in Tribes 2? It has alphabetized lists of usernames.
  • Have you checked IRC functions in Tribes 2? It has alphabetized lists of usernames.
    The IRC uses built-in sort methods on the Username pane, and the IRC servers tend to pass user information in alphabetical order.

    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;
    }
    
  • Yep, the function works as expected. Thanks!
  • ...the IRC servers tend to pass user information in alphabetical order.
    Typing a /names command for #tribes will show you that this is false on the irc.arloria.net server.
Sign In or Register to comment.