You could use the overload of Except
that takes a IEqualityComparer
. The comparer can then be written to only compare strings after the first 20 characters. This way the Except
will compare the strings after the first 20 characters, but will not actually truncate the values returned.
public class AfterTwenty : IEqualityComparer<string>
{
public bool Equals(string x, string y)
{
if (x == null)
{
return y == null;
}
return x.Substring(20) == y.Substring(20);
}
public int GetHashCode(string obj)
{
return obj == null ? 0 : obj.Substring(20).GetHashCode();
}
}
Then you can call Except
like this.
var comparer = new AfterTwenty();
var inFirstNotInSecond = file1Lines.Except(file2Lines, comparer);
var inSecondNotInFirst = file2Lines.Except(file1Lines, comparer);