System Globalization

The global reach of the Internet, which essentially connects every intelligent box in the universe to every other intelligent box in the universe, means that essentially any application can be used by a native speaker of essentially any human language. Presenting numbers and dates in the manner that each user expects and immediately understands is not a matter of cultural sensitivity. It is a critical piece of communication necessary to avoid expensive errors. When you buy your non-refundable airline ticket online, does the departure date of 6-5-02 represent May 6 or June 5? The System.Globalization namespace in the .NET Framework contains classes that provide prefabricated functionality allowing a programmer to write programs that adjust to the language of its user, particularly in the area of formatting dates and numbers.

The class DateTimeFormatInfo provides methods and properties that assist with the formatting of DateTime objects in accordance with a particular culture (a language and optionally a country, such as English and optionally US or Canada). For example, the methods Parse and ParseExact convert input strings into DateTime objects. You fetch the DateTimeFormatInfo for the calling thread's current culture via the static property CurrentInfo, or you can create them directly via the constructor. The DateTimeFormatInfo class implements the interface System.IFormatProvider, which returns the proper date format pattern according to the culture for use in string formatting. You pass the DateTimeFormatInfo to the method DateTime.ToString when you want to format a date. The enumeration DateTimeStyles customizes how the DateTime.Parse and DateTime.ParseExact methods parse a string, for example, specifying whether whitespace is or isn't allowed in the input string.

The class NumberFormatInfo provides methods and properties that assist with the formatting of numeric values according to culture. For example, the property Curren-cySymbol returns the currency symbol in the culture associated with a particular NumberFormatInfo object instance. You fetch the NumberFormatInfo for the calling thread's current culture via the static property CurrentInfo, or you can create them directly via the class constructor. The NumberFormatInfo class implements the interface System.IFormatProvider, which returns the proper number format pattern according to the culture for use in string formatting. You pass the NumberFormatInfo to the method ToString when you want to format a number. The enumeration NumberStyles customizes how the Parse methods of individual numeric types (for example, Int32.Parse) parse a string, for example, whether or not to allow an exponent.

The enumeration UnicodeCategory contains values that denote the various categories of Unicode characters that exist, for example, uppercase letter or lowercase letter. It is the return type of the method System.Char.GetUnicodeCategory.

Was this article helpful?

0 0

Post a comment