I recently realized that Mathematica seems incapable of comparing strings in the "normal" expected lexicographic order. Indeed, for some simulations, I need to process text directly, without fiddling with it, and I would like to have such things as
If["aaa" < "aaaab", 1, 0] (* ---> 1 *)
Min["aaaa", "deaaaf", "dfeef", "a"] (* ---> "a" *)
and so on. However, as far as I can tell this is not possible. Am I wrong? Or is there any work-around, or way for me to use lexicographic ordering? Do I have to code it by hand? Mathematica is so good at getting stuff right out of the box I have a hard time believing it (but this would echo some other contributors comment here, that strings are "second class" citizens in Mathematica)...
stringOrderedQ[s1_String, s2_String] := OrderedQ[Hold[s1, s2]], so thatstringOrderedQ["aaa", "aaaab"] == True/stringOrderedQ["aaaab", "aaa"] == False. – Oleksandr R. Feb 28 '12 at 20:21Orderbecause the OP was already looking for integer output (1, 0), and becauseOrderprovides more information in the case of a tie. – Mr.Wizard Feb 28 '12 at 20:27_Stringon the lhs? – Szabolcs Feb 28 '12 at 20:28OrderedQworks for expressions with anyHead, so anything without theOrderlessattribute will do.Listwould have been fine, in fact. – Oleksandr R. Feb 28 '12 at 20:35