O'Reilly logo

Programming C# 4.0 by Jesse Liberty, Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Culture Sensitivity

Up to this point, we’ve quietly ignored a significantly complicating factor in string manipulation: the fact that the rules for text vary considerably among cultures.

There are also lots of different types of rules in operation, from the characters to use for particular types of separators, to the natural sorting order for characters and strings. I’ve already called out an example where the output on my UK English machine was different from that on a U.S. English computer. As another very simple example, the decimal number we write as 1.8 in U.S. or UK English would be written 1,8 in French. For the .NET Framework, these rules are encapsulated in an object of the type System.Globalization.CultureInfo.

The CultureInfo class makes certain commonly used cultures accessible through static properties. CurrentCulture returns the default culture, used by all the culture-sensitive methods if you don’t supply a specific culture to a suitable overload. This value can be controlled on a per-thread basis, and defaults to the Windows default user locale. Another per-thread value is the CurrentUICulture. By default, this is based on the current user’s personally selected preferred language, falling back on the operating system default if the user hasn’t selected anything. This culture determines which resources the system uses when looking up localized resources such as strings.

Note

CurrentCulture and CurrentUICulture may sound very similar, but are often different. For example, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required