How can i remove the last part in a string
I have a dynamic generated string as /directory/folder/filename.html
How can i remove the last part i.e /filename.html.
I want my output as /directory/folder/.
Use the Path.GetDirectoryName method in System.IO:
string path = "/directory/folder/filename.html"; path = Path.GetDirectoryName(path);
This may change the path seperator to the system default. If you want to preserve the slashes, use the following instead:
path = path.Substring(0, path.LastIndexOf('/'));