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

Sébastien Lorion <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
string s1 = "Straße";
string s2 = "STRASSE";

int ordinal = string.Compare(s1, s2, StringComparison.OrdinalIgnoreCase); //
= 140
int current = string.Compare(s1, s2,
StringComparison.CurrentCultureIgnoreCase); // = 0

OrdinalIgnoreCase does not use Unicode conversion tables for making letters
uppercase. It makes it faster, but also may produce unexpected results. The
end result for non-english users is annoying.

Sébastien
On Mon, Sep 8, 2008 at 3:02 PM, Per Bolmstedt
<[email protected]>wrote:

> Define "won't work". Also, can you shed some more light on why it "won't
> work"?
>
> On Mon, 8 Sep 2008 14:32:02 -0400, =?ISO-8859-1?Q?S=E9bastien_Lorion?=
> <[email protected]> wrote:
>
> >It won't work with international characters.
> >
> >Sébastien
> >On Mon, Sep 8, 2008 at 2:19 PM, Per Bolmstedt
> ><[email protected]>wrote:
> >
> >> On Mon, 8 Sep 2008 13:23:16 -0400, =?ISO-8859-1?Q?S=E9bastien_Lorion?=
> >> <[email protected]> wrote:
> >>
> >>> by using OrdinalIgnoreCase, you are limiting yourself to only the
> >>> first 128 chars of ASCII, which in 2008 is kinda out of fashion...
> >>
> >> How so?
> >>
> >> According to "New Recommendations for Using Strings in Microsoft .NET
> >> "[1]; "Comparisons made using OrdinalIgnoreCase are behaviorally the
> >> composition of two calls: calling ToUpperInvariant on both string
> >> arguments, and doing an Ordinal comparison.".
> >>
> >> 1: http://msdn.microsoft.com/en-us/library/ms973919.aspx
>
> ===================================
> 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.