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的问题。