Re: String.Compare seems to fail when it should not

Ryan Heath <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
Yeah, that will teach me to post some contrived code to the list :)
But the production code is really working that way, String.Compare doesn't
return zero for
strings that seem to be equally to me.

At first I thought the internal representation of the strings where not
equal, so I logged the length of the strings.
But even their lengths are the same! :S

Anyone another idea how to tackle this?

A lot of entries that fail contain an i, so I immediately thought about the
turkish-i problem,
but I have found another entry that failed to without an i in it:
romA vs ROMA

// Ryan

On Fri, Sep 5, 2008 at 4:54 PM, Simon Robinson <[email protected]>wrote:

> It works fine for me (other than that your code doesn't compile because
> you need String.Format(....) inside the exception constructor).
>
> Are you sure there isn't at typo or something in your code?
>
> My test code is:
>
> // code works fine - string.Compare() returns 0 so no exception
> string str1 = "-mylife";
> string str2 = "-MYLIFE";
> if (0 != string.Compare(str1, str2, StringComparison.OrdinalIgnoreCase))
> {
>  string msg = string.Format("Compare failed str1:({0}) length:{1}
> str2:({2}) length:{3}", str1, str1.Length, str2, str2.Length);
>  throw new Exception(msg);
> }
>
> ===================================
> This list is hosted by DevelopMentor(R)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.