Hmmm... just looking at Jon's sample again, and I'm damned if I can
Quote:
get it to successfuly equate... following all also report false /
non-zero:
Console.WriteLine("mail".ToUpper() == "MAIL");
Console.WriteLine("mail".ToUpper() == "MAIL".ToUpper());
>
Console.WriteLine(StringComparer.CurrentCultureIgn oreCase.Equals("mail",
Console.WriteLine(StringComparer.CurrentCultureIgn oreCase.Compare("mail",
Quote:
"MAIL"));
Console.WriteLine(string.Equals("mail", "MAIL",
StringComparison.CurrentCultureIgnoreCase));
Console.WriteLine("mail".Equals("MAIL",
StringComparison.CurrentCultureIgnoreCase));
>
Of course, this is Jon's test case, not yours - so your specific
culture and phrase may be more forgiving... but I don't think I know
about internationalization to give the complete answer... I'll add it
to my list of things to brush up on...
>
So : does anybody know how you *should* realistically compare such?
For all the examples above, as well as for the initial case (the "Windows"
string) the CurrentCulture is the most important factor.
For English:
U+0069 <-U+0049
For Turkish/Azeri
U+0069 <-U+0130
U+0131 <-U+0049
So, for Turkish/Azeri "MAIL" is really NOT ToUpper("mail")
This is how it is, and this is how it *should* be.
Now, sometimes you might need to compare things in a locale-independent way
(ie for file system, comunication protocols (ex: mailto:....), etc.)
The right thing for file system is to try accessing the file
( with _access (_taccess), or PathFileExists, or CreateFile)
For other things use StringComparer.InvariantCultureIgnoreCase( ... )
or String.ToUpperInvariant + String.CompareOrdinal
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email