I have custom IComparer<string>
which I use to compare strings ignoring their case and symbols like this:
public class LiberalStringComparer : IComparer<string>
{
private readonly CompareInfo _compareInfo = CultureInfo.InvariantCulture.CompareInfo;
private const CompareOptions COMPARE_OPTIONS = CompareOptions.IgnoreSymbols | CompareOptions.OrdinalIgnoreCase;
public int Compare(string x, string y)
{
if (x == null) return -1;
if (y == null) return 1;
return this._compareInfo.Compare(x, y, COMPARE_OPTIONS);
}
}
Can I obtain the output string which is, ultimately, used for the comparison?
My final goal is to produce an IEqualityComparer<string>
which ignores symbols and casing in the same way as this comparer.
I can write regex to do this, but there's no guarantee that my regex will use the same logic as the built-in comparison options do.
Equals
you can doyourComparer.Compare(x,y) == 0
– WellIEqualityComparer
... I still will needGetHashCode
– Breakabledecimal
first. – Epicurean