Re: How can this be? Why in c# "a-0".CompareTo("a0") returns 1?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance





"Peter Duniho" wrote:

On Fri, 07 Aug 2009 16:22:01 -0700, G. <G@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Isn't this so sad and too bad? Why the string sort with default
settings
cannot sort these simple strings?

It can. It just happens to not sort them the way you think is the best.

I do not know what others think. But in my opinion, this sorting is
broken.

It's quite clear that that's your opinion. But you are in the minority.

I am using the latest visual studio 2008 express with sp1. Do not know if
this is the case for other versions of VS.

Again, the sorting behavior is defined by the .NET Framework. It has
nothing to do with Visual Studio, or C#.

I would say that string sorting is
so basic and such a problem (default string sort is not what you expect)
is a
big surprise for me.

That you consider string sorting to be "basic" simply illustrates how
naïvely you're looking at the problem. String sorting is not nearly as
simple a problem as you appear to think it is.

I have to say that it is broken, if you have some strings with several -
or
hyphens in it, you cannot expect where it would put those strings.

Actually, you can. The sorting is 100% reproducible.

It is very
strange. I do not know how it sorts strings with - in it at all. It seems
pretty random.

It's not random.

One possible option here is to just let the control sort the way it does
now. That may be just as appropriate for some subset of your users as
the
sorting method you are trying to get instead.

Again, we do not know how the strings are sorted at all.

Yes, we do. I quoted MSDN and provided a link where some of the details
can be found. You could research it yourself if you wanted more detail
than that.

As long as you continue to believe that this is a defect in .NET rather
than a feature, you will make poor progress in achieving your goals. You
need to understand the API you're using if you expect to use it
effectively.


So I take your advice and have some look of the link you have. It appears
that - is assigned some random value that we do not really know and that this
"feature" (might be useful in some cases) considered great in all the case by
some there is thus forced on us now such that we have no choice but to accept
it. Is there something wrong here? Thanks for that.

G.

Pete

.



Relevant Pages

  • Re: Guido rethinking removal of cmp from sort method
    ... The double sort is useless if the actual sorting is done in a different ... should be hidden by the class (or auxiliary comparison function). ... a string forward and another string in reverse. ...
    (comp.lang.python)
  • Re: Selecting records matching user input
    ... I have removed everything from Grouping and Sorting and now ORDER BY in my SELECT query is working as it should. ... SOMETIMES the sort order of the underlying query will be used as the default ... > Dim strCriteria As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: Comparing Two Files line by line and word by word
    ... Sort them, ... out at sorting if you sort yourself or do it after sorting. ... an array of strings where every string is a word, ... array, and generating a string from it containing all the words, ...
    (comp.lang.c)
  • Re: VB6 LISTBOX problem
    ... Have a look at the code below, can you do a sort that is faster ... There are of course all sorts of ways of sorting stuff, especially stuf that is "linked together" as in your UDTs, but to prove the following code sorts it in exactly the same way that your own original code does so, by concatenating all three items of each element into a composite string exactly as you are already doing, but instead of dumping those composite strings into a ListBox it dumps them into a VB string array. ... Private Type SAFEARRAY1D ... Dim StPtr As Long, VAs String, pVAs Long ...
    (microsoft.public.vb.general.discussion)
  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)