打印时,我有NSURL
看起来像这样
控制台:
<AVURLAsset: 0x170232800, URL = assets-library://asset/asset.MOV?id=426C5913-86CF-4476-2DB6-6A9AAC626AF4&ext=MOV>
获取此网址的ID部分的正确方法是什么?目标是使用426C5913-86CF-4476-2DB6-6A9AAC626AF4
字符串。
答案 0 :(得分:3)
您可以使用以下内容:
NSURL *url = [[NSURL alloc] initWithString:@"assets-library://asset/asset.MOV?id=426C5913-86CF-4476-2DB6-6A9AAC626AF4&ext=MOV"];
NSArray *components = [[url query] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"=&"]];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
for (NSUInteger idx = 1; idx < components.count; idx+=2) {
params[components[idx - 1]] = components[idx];
}
NSLog(@"params[@id] = %@", params[@"id"]);
为此目的创建一个NSURL类别是个好主意。
答案 1 :(得分:0)
开始于:
NSURL *urlAddress = [NSURL URLWithString:yourAddressString];
然后:
[urlAddress scheme] gives the Scheme;
[urlAddress host] gives the host
[urlAddress path], [urlAddress relativePath], [urlAddress query], [urlAddress fragment] or [urlAddress parameterString] gives the correspondent parts of your urlAddress