Re: CompareTo issue.

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

From: Ben Spigle (BenSpigle_at_discussions.microsoft.com)
Date: 08/08/04


Date: Sun, 8 Aug 2004 08:57:01 -0700

Hmm... Maybe you can explain what's so hard about sorting strings. In 25
years in computing I have never before encountered a system that couldn't
sort a list of strings. It's a pretty basic requirement in computing.

I'm trying to sort a list to use in a binary search, where the search key
does not have to be completely specified. Here's how the list I gave it
sorted (quotation marks are just to mark the beginning/end of the key.)
"1005-","10050","1005-0","100500","1005-00","1005-00
","100500 ","100501","1005-01",
"1005-01 ","100501 ","1005-1"
Given a key of "10050" you would hope to get "10050","100500","100500
 ". With this screwed up sort, however, the algorithm would terminate when
it it saw "1005-0" so neither "100500" and "100500 " would appear in
the result list.
"Sijin Joseph" wrote:

> When comparing strings less than and greater than are very hard to define,
> the important thing we need to look at is equality.
>
> --
> Sijin Joseph
> http://www.indiangeek.net
> http://weblogs.asp.net/sjoseph
>
>
> "Ben Spigle" <Ben Spigle@discussions.microsoft.com> wrote in message
> news:4DDDFC4C-2B91-4A83-9FD4-4B1724E4BC47@microsoft.com...
> > I have a situtation where CompareTo is returning strange results when
> having
> > dashes in strings. The most concise illustration is:
> > "10050".CompareTo("1005-") = 1
> > "10050".CompareTo("1005-0") = -1
> > I have run alot more tests (I can post a short program if useful), but the
> > rule seems to be - < 0 at the end of a string but - = 0 in the middle of a
> > string.
> >
> > Does anybody know what's going on here?
>
>
>



Relevant Pages

  • Re: Solution for sorting an array alpha-numerically
    ... strings up into groups and sorting the groups seperately, ... > so that numeric and alphabetic data sort as seperate groups. ... To the same project as the web page, add the class AlphaNumCompare() ...
    (microsoft.public.dotnet.general)
  • Re: Friend got a new one
    ... packing under the saddle to raise the action, that sort of thing can really ... Lugged it home, removed the mossy strings, ... I have had 'dog' Martins through the shop over the years, ...
    (rec.music.makers.guitar.acoustic)
  • Re: a question for sorting keys in Map
    ... I have a Map, actually a TreeMap, which will automatically sort the keys ... You can write your own Comparator object which implements the Compare ... strings so that X10 comes after X2 instead of before it. ... Unix ls command sort file names the way you want your strings to sort. ...
    (comp.lang.java.programmer)
  • Re: Detailed explanation of how a QuickSort Works
    ... Static player1 As Object ... But actually loading the data from the mp3 file from the disk and analyzing that data and decompressing it and arranging to stream it in a way that causes the song to be played through your speakers is a fairly complicated task, and almost all programmers will happily leave all that "knowledge" safely in the hands of the Player1 object and will treat it merely as a "black box" in the way I mentioned above. ... when sorting a large number of strings you will find it very much quicker to modify your sort routine so that it sorts "Long pointers" to the strings rather than sorting the string data itself. ...
    (microsoft.public.vb.general.discussion)
  • Re: fast stable sort
    ... Can you post C code for a stable in place mergesort function? ... How do you load a herd of strings into your ... diddles the pointers, not the strings. ... In this case the requirement is to sort the pointers in place ...
    (comp.programming)