Use formatting with the invariant culture to persist non-string data in string form.Īvoid the following practices when you compare strings: Use culture-sensitive formatting to display non-string data, such as numbers and dates, in a user interface.Use the String.Compare and String.CompareTo methods to sort strings, not to check for equality.Use an overload of the String.Equals method to test whether two strings are equal.Use the String.ToUpperInvariant method instead of the String.ToLowerInvariant method when you normalize strings for comparison.Use the non-linguistic StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase values instead of string operations based on CultureInfo.InvariantCulture when the comparison is linguistically irrelevant (symbolic, for example).Use string operations that are based on StringComparison.CurrentCulture when you display output to the user.Use comparisons with StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase for better performance.Use StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase for comparisons as your safe default for culture-agnostic string matching.Typically, this involves calling a method overload that has a parameter of type StringComparison. Use overloads that explicitly specify the string comparison rules for string operations.Examples include String.Equals, String.Compare, String.IndexOf, and String.StartsWith. Various string-related methods perform comparison. NET, follow these recommendations when you compare strings. NET, presents recommendations for selecting an appropriate string-handling method, and provides additional information about string-handling methods. This article examines the string sorting, comparison, and casing methods in. When culturally independent string data, such as XML tags, HTML tags, user names, file paths, and the names of system objects, are interpreted as if they were culture-sensitive, application code can be subject to subtle bugs, poor performance, and, in some cases, security issues. For example, strings that are used internally by an application typically should be handled identically across all cultures. But sorting or comparing strings isn't always a culture-sensitive operation. NET provides extensive support for developing localized and globalized applications, and makes it easy to apply the conventions of either the current culture or a specific culture when performing common operations such as sorting and displaying strings.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |