我在变量中有路径,例如:D:\foo\bar\baz\file.txt
它也可以是这样的:/foo/bar/baz/file.txt
我需要跨平台的方法可以移到bar
目录。
我只找到了一种方法,但它看起来像 hack:writeln(mystr.replaceLast("baz" ~ dirSeparator ~ "file.txt", ""));
最佳答案
std.path
为此有 2 个函数: buildNormalizedPath
和 asNormalizedPath
.
它们之间唯一的区别是asNormalizedPath
不会分配内存。
关于path - D:跨平台方式移动到顶级路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33234620/