DirectoryPath
= C:PicsのC#フィルターの違い
filePath
= C:\ Picsの\ \犬\ dog.PNG
newPath
次のようになります。犬\ dog.PNG
newPath
を入手するにはどうすればよいですか? 私のコードスニペットは、事前に
string directoryPath = "C:\\Pics";
string filePath = "C:\\Pics\\Dogs\\dog.PNG";
if (!directoryPath.EndsWith("\\"))
directoryPath = directoryPath + "\\";
string newPath = filePath.Substring(filePath.LastIndexOf(directoryPath) + 1);
おかげで、右ではありません!
は、[XY問題の場合のように見えます](https://meta.stackexchange.com/a/66378/208223)。相対パスではなく文字列の違いを確認してもよろしいですか? – Theraot
'LastIndexOf'と' IndexOf'は、部分文字列がどこで終わるかを示すインデックスを返します。 – juharr