需要分隔一个字符串 on&
但不是 on &
。
有没有一种更优雅的方式来编写代码,而不是先替换它然后将它分开&
?像这样...
query = [query stringByReplacingOccurrencesOfString:@"&" withString:@"~~~"];
NSArray * kvpairs = [query componentsSeparatedByString:@"&"];
NSMutableArray *mArr = [[NSMutableArray alloc] init];
for (NSString *kvp in kvpairs) {
[mArr addObject:[kvp stringByReplacingOccurrencesOfString:@"~~~" withString:@"&"]];
}
kvpairs = [NSArray arrayWithArray:mArr];
[mArr release];