0

打印到控制台时,我有一个NSURL看起来像这样 :

<AVURLAsset: 0x170232800, URL = assets-library://asset/asset.MOV?id=426C5913-86CF-4476-2DB6-6A9AAC626AF4&ext=MOV>

获取此 URL 的 id 部分的正确方法是什么?目标是有一个字符串426C5913-86CF-4476-2DB6-6A9AAC626AF4

4

2 回答 2

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 类别是个好主意。

于 2013-10-19T10:51:41.570 回答
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
于 2013-10-19T10:52:01.707 回答