There is a string
C:\Folder1\SubFolder1\SubFolder2\SubFolder3 I have to cut everything for the last slash and get
C:\Folder1\SubFolder1\SubFolder2 How to implement it?
There is a string
C:\Folder1\SubFolder1\SubFolder2\SubFolder3 I have to cut everything for the last slash and get
C:\Folder1\SubFolder1\SubFolder2 How to implement it?
Vapiant 1:
var path = @"C:\Folder1\SubFolder1\SubFolder2\SubFolder3"; var result = System.IO.Path.GetDirectoryName(path); For reference: GetDirectoryName
Option 2:
var path = @"C:\Folder1\SubFolder1\SubFolder2\SubFolder3"; int pos = path.LastIndexOf("\\"); // позиция последнего слеша var result = path.Remove(pos, path.Length - pos); Result:
C: \ Folder1 \ SubFolder1 \ SubFolder2
Source: https://ru.stackoverflow.com/questions/581652/
All Articles