by Michael S. Kaplan, published on 2006/08/12 03:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/08/12/696284.aspx
I have spoken of the importance of using .NET 2.0's OrdinalIgnoreCase and Vista's CompareStringOrdinal for comparisons of symbolic identifiers in the past many times.
But not everyone reads this blog, of course. :-)
Just yesterday, a question that was asked kind proves that:
Hi
I was going through this link http://msdn.microsoft.com/netframework/default.aspx?pull=/library/en-us/dndotnet/html/StringsinNET20.asp which encourages usage of StringComparison.Ordinal for filename comparisons. Basically, I would like to understand what will be the response in the following case:
filename.StartsWith(parentname, StringComparison.OrdinalIgnoreCase)
parentname: file1
filename: FILE1TEXT
current culture: Turkish
I believe, in this case it will return true. However, being a Turkish user I would like the call to fail because I is not the upper case of i. In this case how do we make the comparisons.
Cheers
Well, I think I mentioned previously that the New Recommendations for Strings in .NET 2.0 were confusing. Sort of proves my point, huh? :-)
It is natural if one has expectations in one's language for one to expect that the OS will use those same rules. The only problem is that sometimes it doesn't. Especially in this case....
OrdinalIgnoreCase is the way to go in this situation. The only way to go, in fact!
This post brought to you by İ (U+0130, a.k.a. LATIN CAPITAL LETTER I WITH DOT ABOVE)
referenced by
2007/09/23 If it isn't Unicode, it isn't ANY code!
2006/12/04 SQL and the CLR: Part 0