On Wed, Dec 06, 2017 at 10:32:03AM -0800, Ali Çehreli via Digitalmars-d-learn 
wrote:
> On 12/06/2017 04:43 AM, Fredrik Boulund wrote:
> > On Wednesday, 6 December 2017 at 10:42:31 UTC, Dgame wrote:
> >
> >>
> >> Or you simply do
> >> ----
> >> writeln("longword".array.sort);
> >> ----
> >
> > This is so strange. I was dead sure I tried that but it failed for
> > some reason. But after trying it just now it also seems to work just
> > fine.  Thanks! :)
> 
> As a general comment, sorting a string does not make sense in general
> when Unicode is involved.
[...]

Yeah... in general, you need to decide exactly what kind of sorting you
intend.  If you intend to sort individual graphemes (i.e., what we
normally think of as "characters"), you need to segment the string into
graphemes with .byGrapheme and then sort it as an array/range of
graphemes.  Sorting Unicode code points is probably not what you want,
and sorting code units is probably never what you want (unless you're
doing byte frequency analysis on UTF-8 or something :-P).

Unicode is a tricky beast.


T

-- 
What do you get if you drop a piano down a mineshaft? A flat minor.

Reply via email to