I wanted to know if there is anything like "BeforeLastIndexOf
". I'm new to c# and don't really know how "LastIndexOf
" and "IndexOf
" works. What I'm trying to achive is that for example the user types in a directory and it deletes from the string the last folder of this directory but usually directory's look like this "C:\something\something\
" and it has a "\"
at the end, so a code like this doesn't work:
string input = Console.ReadLine();
int index = input.LastIndexOf("/");
if (index > 0)
input = input.Substring(0, index + 1);
Cause it deletes only everything after the last "\"
and it's anyway at the end so it doesn't delete anything