When comparing paths, the path direction of the path separator is also very important. For example:
bool isEqual = String.Equals("myFolder\myFile.xaml", "myFolder/myFile.xaml", StringComparison.OrdinalIgnoreCase);
isEqual will be false .
Therefore, you must first correct the paths:
private string FixPath(string path) { return path.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) .ToUpperInvariant(); }
While this expression will be true :
bool isEqual = String.Equals(FixPath("myFolder\myFile.xaml"), FixPath("myFolder/myFile.xaml"), StringComparison.OrdinalIgnoreCase);
Mr.B Aug 23 '16 at 13:05 2016-08-23 13:05
source share