Is there a way to remove the characters in a string after the last occurrence of a delimiter?
I have looked into the following questions.
Split string by last separator - In this case, the characters before the last occurrence are omitted. But I just need the opposite of this.
Remove last characters from a string in C#. An elegant way? - Here the characters after the first occurrence of the delimiter are removed.
For e.g. I have a string
"D:\dir1\subdir1\subdir11\subdir111\file1.txt"
The result I expect is
"D:\dir1\subdir1\subdir11\subdir111"
Note: This is just an example. I need a solution to work in other cases too.