C# code to sort by alphanumeric

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

Hello

I've written a C# program to sort based upon alphanumeric. May runs with
out error, and works fine, but I have the below as part of my output, and I
can't tell if it's correct or not. I thought CLEAR_ALL would come before
CLEAR_1234 and CLEAR_708

Am I wrong?

CLEAR
CLEAR_1553_BUFFER
CLEAR_708_BUFFER
CLEAR_ALL
CLEAR_SET_NUM
CLEARSEM
 
I've written a C# program to sort based upon alphanumeric. May runs with
out error, and works fine, but I have the below as part of my output, and
I can't tell if it's correct or not. I thought CLEAR_ALL would come
before CLEAR_1234 and CLEAR_708

Am I wrong?

No...as long as you're using EBCDIC!!

An intimate knowledge of the ASCII chart is something I believe every
programmer should have. It would make the reason for the sort order you see
below obvious.
 
An intimate knowledge of the ASCII chart is something I believe every
programmer should have. It would make the reason for the sort order you
see below obvious.

Wait, I just noticed the last item in the list, and I withdraw the "obvious"
comment (although it still applies to the first 5 items). The underscore
comes after captial letters, so I don't know why CLEARSEM would sort to the
end. There must be something else going on here. Anyone have an idea?
 
Wait, I just noticed the last item in the list, and I withdraw the
"obvious"
comment (although it still applies to the first 5 items). The underscore
comes after captial letters, so I don't know why CLEARSEM would sort to
the
end. There must be something else going on here. Anyone have an idea?

Yes. The default sort order weights different characters differently.
Things like hyphens and underscores tend to be ignored for the purpose of
sorting.

One can cause those characters to be full participants in the sort by
specifying a different sort method (e.g. ordinal).

We just had a thread a week or two ago, wherein a fellow was quite irate
that .NET didn't always sort the way _he_ wanted by default. If you want
more details, you might be able to find something useful there (though,
maybe not since the irate fellow didn't seem to).

Pete
 
Yes. The default sort order weights different characters differently.
Things like hyphens and underscores tend to be ignored for the purpose of
sorting.

One can cause those characters to be full participants in the sort by
specifying a different sort method (e.g. ordinal).

Ah, yes, I've run across that before.
 
Back
Top