Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在对象c中按regx过滤字符串_Objective C - Fatal编程技术网

Objective c 如何在对象c中按regx过滤字符串

Objective c 如何在对象c中按regx过滤字符串,objective-c,Objective C,假设有一个字符串 NSString *str = @"https://www.xxx.com?t=aaa&m=bbb&s=92," 现在我想得到t,m,s的值,如下所示: aaa,bbb,92 谁能告诉我如何在对象c中实现它呢?简单的方法就是 NSString *str = @"https://www.xxx.com?t=aaa&m=bbb&s=92,"; NSArray * list = [str componentsSeparatedByCharacte

假设有一个字符串

NSString *str = @"https://www.xxx.com?t=aaa&m=bbb&s=92,"
现在我想得到t,m,s的值,如下所示:

aaa,bbb,92

谁能告诉我如何在对象c中实现它呢?

简单的方法就是

NSString *str = @"https://www.xxx.com?t=aaa&m=bbb&s=92,";

NSArray * list = [str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"?=&,"]];


//Test result    
for (int i = 1; (i+1)<[list count];i = i +2)
{
    NSLog(@"%@ = %@",[list objectAtIndex:i],[list objectAtIndex:(i+1)]);
}
试着这样做:-

    NSString *str1 = @"https://www.xxx.com?t=aaa&m=bbb&s=92,";
    NSMutableArray *arr1=[[str1 componentsSeparatedByString:@"="]mutableCopy];
    [arr1 removeObjectAtIndex:0];
    NSMutableArray *mutArray=[NSMutableArray array];
    for (NSString *str1 in arr1)
    {
        ([str1 length] >3)? [mutArray addObject:[str1 substringToIndex:3]] : [mutArray addObject:[str1 substringToIndex:2]];
    }
    NSLog(@"%@",[mutArray componentsJoinedByString:@","]);

这不是关于Objective-C的问题。