Closed
Description
Recently we've been exploring at FilePath APIs for Swift System, including extension
:
let path: FilePath = "/tmp/archive.tar.gz"
print(path.stem!)
print(path.extension!)
// Prints "archive.tar"
// Prints "gz"
For more complicated cases, a lazy version of the existing split
algorithm could be a handy and efficient (no heap allocations!) way to operate on a path with multiple extensions:
let path: FilePath = "/tmp/archive.tar.gz"
for component in path.basename!.string.lazy.split(separator: ".") {
print(component)
}
// Prints "archive"
// Prints "tar"
// Prints "gz"
Metadata
Metadata
Assignees
Labels
No labels