如何格式化file:///Applications/App%20Store.app存储为字符串"App Store"?我想删除"App%20Store.app"之前的所有内容,并使其在新存储的字符串中自动为%20添加空格.
我的代码从a获取用户输入NSOpenPanel()并将上面显示的结果保存到NSURL变量.
编辑得到它与此一起工作!谢谢
var URLinString : String = selectedApp!.absoluteString!
let newString = URLinString.stringByReplacingOccurrencesOfString("file:///Applications/", withString: "")
let newerString = newString.stringByReplacingOccurrencesOfString("%20", withString: " ")
Run Code Online (Sandbox Code Playgroud)
Ind*_*ore 12
Objective-C的
NSURL *url = [NSURL URLWithString:@"file:///Applications/App%20Store.app"];
NSString *lastComponent = [url lastPathComponent];
NSLog(@"Last path component:%@", lastComponent);
Run Code Online (Sandbox Code Playgroud)
迅速
var url = NSURL(string:"file:///Applications/App%20Store.app")
var lastComponent = url?.lastPathComponent
println("\(lastComponent)")
if lastComponent == "App Store.app" {
println("Yes")
}
Run Code Online (Sandbox Code Playgroud)
安慰
Optional("App Store.app")
Yes
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7738 次 |
| 最近记录: |