4
$\begingroup$

Sorting ASCII phrases works fine:

Sort[{"albatrob", "abo", "dict", "star", "mangel", "m"}]
(*{"abo", "albatrob", "dict", "m", "mangel", "star"}*)

But unless I'm misunderstanding something (which seems likely), sorting Unicode words doesn't work as I'd expect:

Sort[{"ɝ", "ʃ", "ɝˈs"}]
(*{"ɝ", "ʃ", "ɝˈs"}*)

How does one sort Unicode words?

$\endgroup$

1 Answer 1

4
$\begingroup$

I don't know what bases you want to sort Unicode words with but why not try sort based on CharacterCode of first Unicode letter:

FromCharacterCode[SortBy[ToCharacterCode[{"ɝ", "ʃ", "ɝˈs"}], First]]

(*{"ɝ", "ɝˈs", "ʃ"}*)

Based on your comment this could be one solution:

n = Max[Length /@ ToCharacterCode[{"ɝz", "ɝaz", "ʃ"}]];
FromCharacterCode[ Sort[PadRight[#, n] & /@ ToCharacterCode[{"ɝz", "ɝaz", "ʃ"}]]]
(*{"ɝaz","ɝz", "ʃ"}*)
$\endgroup$
3
  • $\begingroup$ Thanks for the help. Unfortunately, this only sorts words up to their first letter, and does not sort properly after that. For example, FromCharacterCode[SortBy[ToCharacterCode[{"ɝz", "ɝaz", "ʃ"}], First]] gives {"ɝz", "ɝaz", "ʃ"}, which is not sorted, since ɝaz alphabetically comes before ɝz. $\endgroup$ Mar 21, 2015 at 23:40
  • $\begingroup$ @DumpsterDoofus, Well, this can be solved :n = Max[Length /@ ToCharacterCode[{"ɝz", "ɝaz", "ʃ"}]]; FromCharacterCode[ Sort[PadRight[#, n] & /@ ToCharacterCode[{"ɝz", "ɝaz", "ʃ"}]]] $\endgroup$ Mar 21, 2015 at 23:56
  • $\begingroup$ That seems workable. Thanks and +1! I'll await 24 hours to accept just in case there are other answers. $\endgroup$ Mar 22, 2015 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.