I would like to compare two strings containing file paths in c#.
However, since in ntfs the default is to use case insensitive paths, I would like the string comparison to be case insensitive in the same way.
However I can't seem to find any information on how ntfs actually implements its case insensitivity. What I would like to know is how to perform a case insensitive comparison of strings using the same casing rules that ntfs uses for file paths.
From MSDN:
And:
Therefore it's simply:
(I always use the static
Equals
call in case the left operand isnull
)While comparison of paths the path's separator direction is also very important. For instance:
isEqual
will befalse
.Therefore needs to fix paths first:
Whereas this expression will be
true
:Do you mean this or did i not get the question?
I would go for
or if you want to specify cultures:
using ToUpper does a useless memory allocation every time you compare something