从URL路径中删除file:///前缀

but*_*aby 3 objective-c ios

如何从URL文件路径中删除file:///前缀:

 NSLog(@"File downloaded to: %@", filePath);
Run Code Online (Sandbox Code Playgroud)

当前它打印为:

file:///Users/Library/Developer/CoreSimulator/Devices/EF752245-9692-4607-B84C-6133202A846B/data/Containers/Data/Application/08686F05-C513-4BDF-A20C-EF3AE1201D54/Documents/2017-02-12_1476366438.zip
Run Code Online (Sandbox Code Playgroud)

编辑:

我想我可以做到的:

NSLog(@"File downloaded to: %@", [[filePath absoluteString] stringByReplacingOccurrencesOfString:@"file:///" withString:@""]);
Run Code Online (Sandbox Code Playgroud)

但是在NSString上没有构建可以删除该前缀的任何东西吗?

Rob*_*ier 5

filePath.path是您要寻找的。您不想“删除” file:///。您只需要URL的路径部分。

请注意,这将离开第一个/。我想您可以删除它,但是目前尚不清楚为什么这是一个好主意,因为它是路径的一部分。(如果将其与可能以结尾的其他字符串粘合在一起/,则最好使用路径方法,例如stringByAppendingPathComponent:摆脱双斜杠。)