Convert string to uppercase when comparing after normalizing instead of lowercase
Posted on 8/5/2010 4:48:16 PM
in #Dot Net Framework
While doing string comparison after normalizing (converting both string to upper case or lower case) we should always use the upper case. Upper case is optimized for normalization./o:p>/P>
/SPAN>A small group of characters, when they are converted to lowercase, cannot make a round trip. To make a round trip means to convert the characters from one locale to another locale that represents the same character data differently, and then to accurately retrieve the original characters from the converted characters./o:p>/P>
Converting to uppercase rather than lowercase can also prevent incorrect behavior in certain cultures. For example, in Turkish, two lowercase i's map to the same uppercase I./o:p>/P>
Vikram/o:p>/P>
|
Posted on 8/12/2010 8:02:25 PM
I would recommend using the static String.Equals method (three arguments.
/p>
public static bool Equals(
string a,
string b,
StringComparison comparisonType
)
/p>
This allows you to check for equality either case sensitive or not, using a culture sensitive comparison or not as well as being able to use ordinal comparison rules. In addition, because it is a static method you don't have to worry about testing the strings being compared for "null" as you would if you wanted to upper case them.
/p>
|