stringByReplacingOccurrence不替换字符串

Sam*_*cer 2 parsing objective-c nsfilemanager ios

我需要解析我的应用程序中的FILE URL,并将%20替换为SPACE.我正在使用stringByReplacingOccurance:

NSString *strippedContent = [finalFilePath stringByReplacingOccurrencesOfString:@"%20" withString:@" "];
Run Code Online (Sandbox Code Playgroud)

但是当我在NSLog中显示strippedContent时,所有%20字符串仍然存在.这是我希望解析的文件名的示例:

.../Documents/Inbox/Test%20Doc%20From%20Another%20App.txt
Run Code Online (Sandbox Code Playgroud)

似乎NSFileManager在其中包含%20时无法找到该文档.文件路径通过"Open In ..."对话框从另一个应用程序传递.有没有办法用stringByReplacingOccurrence删除%20或导入URL?

das*_*ght 9

NSString 提供了一种执行所需转换的方法:

NSString *strippedContent = [finalFilePath stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Run Code Online (Sandbox Code Playgroud)