There is probably not such an "output string". I'd implement your Equals
in this way:
return liberalStringComparer.Compare(x, y) == 0;
GetHashCode
is more complicated.
Some approaches:
- Use a poor implementation like
return 0;
(which means you always have to run aCompare
to know if they're equal). Since your comparison is relatively simple (invariant culture, ordinal ignore case comparison), you should be able to make a hash that generally works. Without extensive study of Unicode and testing, however, I wouldn't recommend that you assume this'll work for any valid Unicode string from any culture.
In pseudocode:
public int GetHashCode(string value) { // for each index in value if (!char.IsSymbol(value, i)) // add value[i].ToUpperInvariant() to the hash using an algorithm // like http://stackoverflow.com/a/263416/781792 }
- Form a string by removing all where
char.IsSymbol
istrue
, then useStringComparer.InvariantCulture.GetHashCode
on it. CompareInfo.GetSortKey
's hash code should be a suitable value.public int GetHashCode(string value) { return _compareInfo.GetSortKey(value, COMPARE_OPTIONS).GetHashCode(); }