int index = 0;
while (true)
{
index = fd.SelectedPath.IndexOf("D"); // never get to the if index -1 to check why !
if (index == -1)
{
break;
}
string sub = fd.SelectedPath.Substring(index, 2);
}
sub is D: if i select the path D in the browser.
This is good i want to get only the D:
But its never getting out the loop its keep looping without stop.
Why it doesn’t get into the -1 if?
On each iteration the
indexOf()method will starts search from the begining of string so you need to setstartIndexparameter or you can useSystem.IO.Path.GetPathRoot(path)method.