It will gracefully handle unicode (those simply are later code points and thus will have larger values) and longer strings (by only looking at the first character). Capitals, numbers, and some symbols will appear as negative numbers since their code points come before a.
Previous answer: I think you're looking for sortperm. It gives you a vector of indices that, if you index back into the original array with it, will put it in sorted order.
Edit: If you're looking for the numeric distance from
'a'
, here's one solution:It will gracefully handle unicode (those simply are later code points and thus will have larger values) and longer strings (by only looking at the first character). Capitals, numbers, and some symbols will appear as negative numbers since their code points come before
a
.Previous answer: I think you're looking for
sortperm
. It gives you a vector of indices that, if you index back into the original array with it, will put it in sorted order.