473,657 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CompareTo issue.

I have a situtation where CompareTo is returning strange results when having
dashes in strings. The most concise illustration is:
"10050".Compare To("1005-") = 1
"10050".Compare To("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?
Jul 21 '05 #1
3 1347
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 Sp****@discussi ons.microsoft.c om> wrote in message
news:4D******** *************** ***********@mic rosoft.com...
I have a situtation where CompareTo is returning strange results when having dashes in strings. The most concise illustration is:
"10050".Compare To("1005-") = 1
"10050".Compare To("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?

Jul 21 '05 #2
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","10 05-00","1005-00
","100500 ","100501","100 5-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 Sp****@discussi ons.microsoft.c om> wrote in message
news:4D******** *************** ***********@mic rosoft.com...
I have a situtation where CompareTo is returning strange results when

having
dashes in strings. The most concise illustration is:
"10050".Compare To("1005-") = 1
"10050".Compare To("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?


Jul 21 '05 #3
You're right, actually i was not thinking from that perspective. Anyways i
dug through the BCL code and then through Rotor, i have finally found the
code that String class in .Net uses for string comparison. It is is
\Rotor\sscli\cl r\src\classlibn ative\nls\comnl sinfo.cpp , go through the code
in this method, it sheds a lot of light on the workings of string
comparison. I haven't had the time to go through the code in detail, but
from what i see there is significant algorithm variance based on case
sensitivity, are you using a case sensitive search?
--
Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
"Ben Spigle" <Be*******@disc ussions.microso ft.com> wrote in message
news:BA******** *************** ***********@mic rosoft.com...
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","10 05-00","1005-00
","100500 ","100501","100 5-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 Sp****@discussi ons.microsoft.c om> wrote in message
news:4D******** *************** ***********@mic rosoft.com...
I have a situtation where CompareTo is returning strange results when

having
dashes in strings. The most concise illustration is:
"10050".Compare To("1005-") = 1
"10050".Compare To("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?


Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5424
by: majm | last post by:
I'm trying to implement strongly typed lists in the 2.0 framework. I'm using VS2005 beta 2. So far, System.Collections.Generic.List appears to be the ideal solution. However, the generic.List.IndexOf function doesn't appear to be invoking the contained class' CompareTo method. My understanding is that it should. The contained class (IssStruct) implements the IComparable and IComparable<T> interfaces. However, the List.Sort function...
3
290
by: Ben Spigle | last post by:
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?
3
1576
by: Fir5tSight | last post by:
Hi All, I have an interface class defined as follows: class FileName : IComparable { public FileName(string fileName, string packageName) { // // TODO: Add constructor logic here
2
9574
by: tony | last post by:
Hello! I have a class lets call it Test with four fields. This Test class implement IComparable so CompareTo is therefore implemented in this Test class. One field in this Test class is an int called Order. The other are of type double called EAF, C_min, C_aim and C_max I implement this CompareTo but I have run into some problems.
4
2166
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any help on this, Benny
3
1810
by: Dhananjay | last post by:
Hi All, I am facing problem when i am converting C#.net code(Delegate concept) into vb.net. I am unable to do that . Can someone help me to solve the problem. I am providing my C#.net code. ==================================my code is :- ====================================== static public List<MembershipUserWrapperGetMembers(bool
2
1269
by: Tony | last post by:
Hello! I have method CompareTo written below. But I have a problem because I want to sort on HeatNumber which is of type int and if this is the same on MspName which is a string. But according to the compiler I'm not allowed to use < on string. So my question is how do I solve this problem. The object Item is stored in an ArrayList.
2
1740
by: Jon Skeet [C# MVP] | last post by:
Author <gnewsgroup@gmail.comwrote: Where? It looks to me like it's calling double's implementation of CompareTo. -- Jon Skeet - <skeet@pobox.com> Web site: http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon_skeet C# in Depth: http://csharpindepth.com
3
10550
by: raylopez99 | last post by:
This is an example of using multiple comparison criteria for IComparer/ Compare/CompareTo for List<and Array. Adapted from David Hayden's tutorial found on the net, but he used ArrayList so the format was different. Basically you can sort a class having members LastName (string), FirstName (string) and Age (int) according to whether you want to sort by Last Name, First Name or Age, using the .Sort function
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.