我试图模仿“cd ..”的作用,但不使用Getparent()。
输入:/ var / mobile / Documents /
实际输出:/ var / mobile / Documents /
所需的输出:/ var / mobile /
public ArrayList JumpUpDirectory()
{
ArrayList directoryListing = new ArrayList();
StringBuilder storedPath = new StringBuilder();
foreach (var directories in storedPreviousDirectory.Split('/'))
{
storedPath.Append(directories + "/");
}
storedPath.Replace("//", "/");
directoryListing = iPhoneFileSystemBrowse(storedPreviousDirectory);
return directoryListing;
}
答案 0 :(得分:1)
试试这个:
string input = "/var/mobile/Documents/";
var parts = input.Split(new []{'/'}, StringSplitOptions.RemoveEmptyEntries).ToList();
parts.RemoveAt(parts.Count - 1);
string output = string.Concat("/", string.Join("/", parts), "/");