I live in Turkey and I need to capitalize a key in my program. I had to use ToUpper(new CultureInfo("en-US", false)) instead of ToUpper() because this function behaves different in computers that are set to Turkish culture(See below picture). Then i saw there is also culture invariant upper function: ToUpperInvariant().
I searched but i could not find any information difference between these functions. Is there any difference at all?
source:http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html
ToUpper()
is the same as ToUpper(CultureInfo.CurrentCulture)
,
whereas ToUpperInvariant()
is the same as ToUpper(CultureInfo.InvariantCulture)
, the comments hint that you already figured that out.
So of course there is a difference here - CultureInfo.InvariantCulture
should only be used when not interacting with humans (parsers etc), as it gives a consistent result, whereas ToUpper(CultureInfo.CurrentCulture
) varies quite a lot between computers, servers, etc.
CultureInfo.InvariantCulture
is an english-inspired culture similar to but is not equal to en-US and is not bound to any country or region, and cannot be customized by users (as explicitly stated in the documentation).
As to explicitly answer your question regarding ToUpper
- yes there are differences. In all of those cases (presented below), ToUpperInvariant()
is the same char
as the lowercase source:
lc en-US Invariant
== ===== =========
µ Μ µ
ı I ı
ſ S ſ
Dž DŽ Dž
Lj LJ Lj
Nj NJ Nj
Dz DZ Dz
ͅ Ι ͅ // ͅͅͅͅͅͅͅthis one lives in the 4th dimension.
ς Σ ς
ϐ Β ϐ
ϑ Θ ϑ
ϕ Φ ϕ
ϖ Π ϖ
ϰ Κ ϰ
ϱ Ρ ϱ
ϵ Ε ϵ
ẛ Ṡ ẛ
ι Ι ι
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With